Swordsman Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
Lawson is a magic swordsman with k kinds of magic attributes v1,v2,v3,…,vk. Now Lawson is faced with n monsters and the i-th monster also has k kinds of defensive attributes ai,,ai,,ai,,…,ai,k. If v1≥ai, and v2≥ai, and v3≥ai, and … and vk≥ai,k, Lawson can kill the i-th monster (each monster can be killed for at most one time) and get EXP from the battle, which means vj will increase bi,j for j=,,,…,k.
Now we want to know how many monsters Lawson can kill at most and how much Lawson's magic attributes can be maximized. Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line has two integers n and k (≤n≤,≤k≤).
The second line has k non-negative integers (initial magic attributes) v1,v2,v3,…,vk.
For the next n lines, the i-th line contains 2k non-negative integers ai,,ai,,ai,,…,ai,k,bi,,bi,,bi,,…,bi,k.
It's guaranteed that all input integers are no more than 109 and vj+∑i=1nbi,j≤109 for j=1,2,3,…,k. It is guaranteed that the sum of all n ≤×.
The input data is very large so fast IO (like `fread`) is recommended. Output
For each test case:
The first line has one integer which means the maximum number of monsters that can be killed by Lawson.
The second line has k integers v′,v′,v′,…,v′k and the i-th integer means maximum of the i-th magic attibute. Sample Input Sample Output Hint For the sample, initial V = [, , ]
① kill monster # (, , ), V + [, , ] = [, , ]
② kill monster # (, , ), V + [, , ] = [, , ]
对于 k 种防御属性,分开进行从小到大排序,设立 k 个指针从最小处开始往最大处移动,对满足被杀死的条件的属 性进行标记
,当某只 monster 的所有防御属性都被标记时,更新剑士的魔法属性同时更新指针往后移动。时间复 杂度 O(kn log n)
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct node{
int val;
int id;
}a[][];
int b[][];
int sum[];
bool cmp(node p,node q)
{
return p.val<q.val;
}
#define fi(n) FastIO::read(n) namespace FastIO {
const int SIZE = << ;
char buf[SIZE], obuf[SIZE], str[];
int bi = SIZE, bn = SIZE, opt;
int read(char *s) {
while (bn) {
for (; bi < bn && buf[bi] <= ' '; bi++);
if (bi < bn) break;
bn = fread(buf, , SIZE, stdin);
bi = ;
}
int sn = ;
while (bn) {
for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi];
if (bi < bn) break;
bn = fread(buf, , SIZE, stdin);
bi = ;
}
s[sn] = ;
return sn;
}
bool read(int& x) {
int n = read(str), bf; if (!n) return ;
int i = ; if (str[i] == '-') bf = -, i++; else bf = ;
for (x = ; i < n; i++) x = x * + str[i] - '';
if (bf < ) x = -x;
return ;
}
};
int main()
{
int t;
fi(t);
while(t--)
{
int n,m;
fi(n);
fi(m);
memset(sum,,sizeof sum);
int pq[];
for(int i=;i<=m;i++)
{
fi(pq[i]);
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
fi(a[j][i].val);
a[j][i].id = i;
}
for(int j=;j<=m;j++)
fi(b[j][i]);
}
for(int i=;i<=m;i++)
sort(a[i]+,a[i]++n,cmp);
int zhizhen[]={,,,,,};
int pppp=;
while()
{
int pp=;
for(int i=;i<=m;i++)
{
while(a[i][zhizhen[i]].val<=pq[i]&&zhizhen[i]<=n)
{ sum[a[i][zhizhen[i]].id]++;
if(sum[a[i][zhizhen[i]].id]==m)
{
pp++;
pppp++;
for(int j=;j<=m;j++)
{
pq[j]+=b[j][a[i][zhizhen[i]].id]; }
}
zhizhen[i]++; }
}
if(pp==)
break; }
cout<<pppp<<endl;
for(int i=;i<=m;i++)
{ if(i!=)
cout<<" ";
cout<<pq[i];
}
cout<<endl; } return ;
}