ACM集训二分E题勇士打怪兽

打n个怪兽,怪兽和勇士都有k个属性,只有每个属性都大于等于怪兽时才能将怪兽击败,
打败怪兽可以增加对应的属性值,问最多能击败多少个怪兽以及最终自己的属性值分别是多少
这道题还要什么输入挂??

Swordsman

Lawson is a magic swordsman with kk kinds of magic attributes v1,v2,v3,…,vkv1,v2,v3,…,vk. Now Lawson is faced with nn monsters and the ii-th monster also has kkkinds of defensive attributes ai,1,ai,2,ai,3,…,ai,kai,1,ai,2,ai,3,…,ai,k. If v1≥ai,1v1≥ai,1 and v2≥ai,2v2≥ai,2 and v3≥ai,3v3≥ai,3 and …… and vk≥ai,kvk≥ai,k, Lawson can kill the ii-th monster (each monster can be killed for at most one time) and get EXP from the battle, which means vjvj will increase bi,jbi,j for j=1,2,3,…,kj=1,2,3,…,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 TT, indicating the number of test cases. For each test case: 
The first line has two integers nn and kk (1≤n≤105,1≤k≤51≤n≤105,1≤k≤5). 
The second line has kk non-negative integers (initial magic attributes) v1,v2,v3,…,vkv1,v2,v3,…,vk. 
For the next nn lines, the ii-th line contains 2k2knon-negative integers ai,1,ai,2,ai,3,…,ai,k,bi,1,bi,2,bi,3,…,bi,kai,1,ai,2,ai,3,…,ai,k,bi,1,bi,2,bi,3,…,bi,k. 
It's guaranteed that all input integers are no more than 109109 and vj+∑i=1nbi,j≤109vj+∑i=1nbi,j≤109 for j=1,2,3,…,kj=1,2,3,…,k. 

It is guaranteed that the sum of all n ≤5×105≤5×105.
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 kk integers v′1,v′2,v′3,…,v′kv1′,v2′,v3′,…,vk′and the ii-th integer means maximum of the ii-th magic attibute. 

Sample Input

1
4 3
7 1 1
5 5 2 6 3 1
24 1 1 1 2 1
0 4 1 5 1 1
6 0 1 5 3 1

Sample Output

3
23 8 4 

Hint

For the sample, initial V = [7, 1, 1]
① kill monster #4 (6, 0, 1), V + [5, 3, 1] = [12, 4, 2]
② kill monster #3 (0, 4, 1), V + [5, 1, 1] = [17, 5, 3]
③ kill monster #1 (5, 5, 2), V + [6, 3, 1] = [23, 8, 4]
After three battles, Lawson are still not able to kill monster #2 (24, 1, 1)
because 23 < 24.

下面是翻译
 

劳森是一个神奇的剑士,拥有k种魔法属性v1,v2,v3,...,vk。现在劳森面临着n个怪物,第i个怪物也有k种防御属性ai,1,ai,2,ai,3,...,ai,k。如果v1≥ai,1和v2≥ai,2和v3≥ai,3和...以及vk≥ai,k,Lawson可以杀死第i个怪物(每个怪物最多可以杀死一次)并获得EXP从战斗中,这意味着vj将增加bi,j为j = 1,2,3,...,k。
现在我们想知道Lawson最多可以杀死多少怪物以及Lawson的魔法属性可以最大化多少。
输入
有多个测试用例。第一行输入包含一个整数T,表示测试用例的数量。对于每个测试用例:
第一行有两个整数n和k(1≤n≤105,1≤k≤5)。
第二行具有k个非负整数(初始魔术属性)v1,v2,v3,...,vk。
对于接下来的n行,第i行包含2k个非负整数ai,1,ai,2,ai,3,...,ai,k,bi,1,bi,2,bi,3,...,bi ,K。
保证所有输入整数不超过109且vj +Σi= 1nbi,对于j = 1,2,3,...,k,j≤109。

保证所有n的总和≤5×105。
输入数据非常大,因此建议使用快速IO(如`fread`)。
产量
对于每个测试用例:
第一行有一个整数,表示可以被Lawson杀死的最大怪物数量。
第二行具有k个整数v'1,v'2,v'3,...,v'k,并且第i个整数意味着第i个魔法属性的最大值。
样本输入
1
4 3
7 1 1
5 5 2 6 3 1
24 1 1 1 2 1
0 4 1 5 1 1
6 0 1 5 3 1
样本输出
3
23 8 4


        
  
暗示
对于样本,初始V = [7,1,1]
①杀死怪物#4(6,0,1),V + [5,3,1] = [12,4,2]
②杀死怪物#3(0,4,1),V + [5,1,1] = [17,1,5]
③杀死怪物#1(5,5,2),V + [6,3,1] = [23,8,4]
经过三场战斗,劳森仍然无法杀死怪物#2(24,1,1)
因为23 <24。

 

你可能感兴趣的:(二分)