题目:每个怪兽有k种防御属性,剑士有m个魔法属性,杀死一个monster需要m个属性都要大于等于这monster相应的防御值,然后剑士的m个魔法属性值都会相应的加上val[i]...val[m].问剑客最多能杀多少monster,并且输出最后的各个魔法属性值。
#include <bits/stdc++.h>
using namespace std;
namespace fastIO {
#define BUF_SIZE 100000
//fread -> read
bool IOerror = 0;
inline char nc() {
static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
if(p1 == pend) {
p1 = buf;
pend = buf + fread(buf, 1, BUF_SIZE, stdin);
if(pend == p1) {
IOerror = 1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline void read(int &x) {
char ch;
while(blank(ch = nc()));
if(IOerror)
return;
for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
}
#undef BUF_SIZE
};
using namespace fastIO;
const int maxn=1e5+10;
struct node{
int x,id;
}a[6][maxn];
bool cmp(const node &a,const node &b)
{
return a.x<b.x;
}
int val[maxn][6];
int n,t,ans[6],m,p[6];
int book[maxn];
void init()
{
//scanf("%d%d",&n,&m);
read(n);read(m);
for(int i=1;i<=m;i++)
read(ans[i]);
//scanf("%d",&ans[i]);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
read(a[j][i].x);
//scanf("%d",&a[j][i].x);
a[j][i].id=i;
}
for(int j=1;j<=m;j++)
read(val[i][j]);
//scanf("%d",&val[i][j]);
}
}
int main()
{
//freopen("in.txt","r",stdin);
//scanf("%d",&t);
read(t);
while(t--)
{
init();
for(int i=1;i<=m;i++)
sort(a[i]+1,a[i]+n+1,cmp);
for(int i=1;i<=m;i++) p[i]=1;
memset(book,0,sizeof book);
int num=0;
while(1)
{
int flag=0;
for(int i=1;i<=m;i++)
{
while(p[i]<=n&&a[i][p[i]].x<=ans[i])
{
int k=a[i][p[i]].id;
book[k]++;
if(book[k]==m)
{
flag=1;
for(int j=1;j<=m;j++)
ans[j]+=val[k][j];
num++;
}
p[i]++;
}
}
if(!flag)
break;
}
printf("%d\n",num);
for(int i=1;i<m;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[m]);
}
return 0;
}