题目链接

Problem Description

Lawson is a magic swordsman with kkk kinds of magic attributes v1,v2,v3,…,vk" role="presentation">v1,v2,v3,…,vkv1,v2,v3,…,vkv_1, v_2, v_3, \dots, v_k. Now Lawson is faced with nnn monsters and the i" role="presentation">iii-th monster also has kkk kinds of defensive attributes ai,1,ai,2,ai,3,…,ai,k" role="presentation">ai,1,ai,2,ai,3,…,ai,kai,1,ai,2,ai,3,…,ai,ka_{i,1}, a_{i,2}, a_{i,3}, \dots, a_{i, k}. If v1≥ai,1v1≥ai,1v_1\geq a_{i,1} and v2≥ai,2v2≥ai,2v_2\geq a_{i,2} and v3≥ai,3v3≥ai,3v_3\geq a_{i,3} and ……\dots and vk≥ai,kvk≥ai,kv_k\geq a_{i, k}, Lawson can kill the iii-th monster (each monster can be killed for at most one time) and get EXP from the battle, which means vj" role="presentation">vjvjv_j will increase bi,jbi,jb_{i,j} for j=1,2,3,…,kj=1,2,3,…,kj = 1, 2, 3, \dots, 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 TTT, indicating the number of test cases. For each test case:The first line has two integers n" role="presentation">nnn and kkk (1≤n≤105,1≤k≤5" role="presentation">1≤n≤105,1≤k≤51≤n≤105,1≤k≤51\leq n \leq 10^5, 1\leq k \leq 5).The second line has kkk non-negative integers (initial magic attributes) v1,v2,v3,…,vk" role="presentation">v1,v2,v3,…,vkv1,v2,v3,…,vkv_1, v_2, v_3, \dots, v_k.For the next nnn lines, the i" role="presentation">iii-th line contains 2k2k2k non-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,ka_{i,1}, a_{i,2}, a_{i,3}, \dots, a_{i, k}, b_{i,1}, b_{i,2}, b_{i,3}, \dots, b_{i, k}.It’s guaranteed that all input integers are no more than 10910910^9 and vj+∑i=1nbi,j≤109vj+∑i=1nbi,j≤109v_j + \displaystyle\sum_{i=1}^n b_{i,j} \leq 10^9 for j=1,2,3,…,kj=1,2,3,…,kj = 1, 2, 3, \dots, k.It is guaranteed that the sum of all n ≤5×105≤5×105\leq 5 \times 10 ^ 5.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 kkk integers v1′,v2′,v3′,…,vk′" role="presentation">v′1,v′2,v′3,…,v′kv1′,v2′,v3′,…,vk′v_1', v_2', v_3', \dots, v_k' and the iii-th integer means maximum of the i" role="presentation">iii-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.

AC

  • 优先队列循环模拟每个属性,满足当前属性的妖怪进入这个队列,直到最后一个队列没有怪物,每次技能加上最后一个队列的怪物的加成
  • 这个题要加上读写挂,如果你写的代码超时,先试试我这个挂
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#define N 100005
#define ll long long
#define P pair<int, int>
#define mk make_pair
// 加快读写
namespace IO {const int MX = 4e7;char buf[MX]; int c, sz;void begin() {c = 0;sz = fread(buf, 1, MX, stdin);}inline bool read(int &t) {while(c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;if(c >= sz) return false;bool flag = 0; if(buf[c] == '-') flag = 1, c++;for(t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++) t = t * 10 + buf[c] - '0';if(flag) t = -t;return true;}
}
using namespace std;
int v[10], a[N][15];using namespace IO;
int main() {
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endif
begin();priority_queue<P, vector<P>, greater<P> >q[15];int t;read(t);while (t--) {int n, k, sum = 0;read(n);read(k);for (int i = 1; i <= k; ++i) read(v[i]);for (int i = 1; i <= n; ++i) for (int j = 1; j <= 2 * k; ++j) read(a[i][j]);for (int i = 1; i <= n; ++i) {q[0].push(mk(a[i][1], i));}while (1) {// 对队列进行循环 for (int i = 0; i < k; ++i) {while (! q[i].empty()) {P t = q[i].top();if (t.first > v[i + 1]) break;q[i].pop();q[i + 1].push(mk(a[t.second][i + 2], t.second));}}if (q[k].empty())   break;while (!q[k].empty()) {P t = q[k].top();q[k].pop();for (int i = 1; i <= k; ++i) {v[i] += a[t.second][i + k];}sum++;}}// 注意输出格式 printf("%d\n%d", sum, v[1]);for (int i = 2; i <= k; ++i) {printf(" %d", v[i]);}   printf("\n");// 清空队列 for (int i = 0; i <= k; ++i) {while (!q[i].empty()) {q[i].pop();}}} return 0;
} 

HDU Problem - 6396 Swordsman(优先队列,模拟)相关推荐

  1. HDU Problem - 5935 Car(模拟)

    题目链接 Problem Description Ruins is driving a car to participating in a programming contest. As on a v ...

  2. 【CodeForces - 1038C】Gambling (博弈问题,优先队列模拟,贪心)

    题干: Two players A and B have a list of nn integers each. They both want to maximize the subtraction ...

  3. HDU 4857 拓扑排序 优先队列

    n个数,已经有大小关系,现给m个约束,规定a在b之前,剩下的数要尽可能往前移.输出序列 大小关系显然使用拓扑结构,关键在于n个数本身就有大小关系,那么考虑反向建图,优先选择值最大的入度为零的点,这样得 ...

  4. Problem E: 穷游中国在统题 优先队列 + 模拟

    http://www.gdutcode.sinaapp.com/problem.php?cid=1049&pid=4 Problem E: 穷游中国在统题 Description Travel ...

  5. Hdu 1434 幸福列车【优先队列模拟】

    幸福列车 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Submi ...

  6. 【HDU - 1022】Train Problem I (栈模拟,水题,思维)

    题干: As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want t ...

  7. HDU Problem 4857 逃生【拓扑排序+优先队列】

    逃生 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  8. hdu 6396 Swordsman

    题目:点击打开链接 题意:打小怪兽的题目,主角有k个技能,每个技能有对应的攻击力ai,怪兽有k个防御值bi,k个强化能量ci.只有所有的ai > = bi,这只小怪兽才会被打死.然后主角的技能就 ...

  9. hdu 6396 Swordsman (技巧)

    大意: n个怪, m种能力值, 当自己所有能力值不低于某只怪时可以杀死它, 并获得它的所有能力, 求最大杀几只 将每只怪拆成$m$个, 排下序贪心即可, 复杂度$O(nm)$, 原题极其卡时间, 我的 ...

最新文章

  1. flask 获取网址
  2. CentOS 7.0安装Nvidia驱动
  3. java8多线程运行程序_线程,代码和数据–多线程Java程序实际运行的方式
  4. Hibernate(7)关联关系_单向1对n
  5. opencv 纸箱分割_OpenCV与AIPCV库——学习笔记(一)
  6. IE6下链接onclick事件处理中的请求被aborted
  7. Enterprise Library 2.0 Hands On Lab 翻译(2):数据访问程序块(二)
  8. Springboot的工作机制:2 @SpringBootApplication背后的秘密
  9. Python-《转载-Github上的python开源项目》
  10. 【论文阅读笔记】FCOS代码结合论文阅读
  11. C#阿里云短信接口API开发步骤
  12. 第7周编程题在线测试
  13. FreeRTOS软件定时器 基于STM32
  14. 最高效寻找重复数据,如何高效率的查找到数组中的重复值
  15. 【有限元分析】异型密封圈计算泄漏量与参数化优化过程(带分析源文件)
  16. uniapp 即时通讯_uni-App 仿微信 App 即时通讯|vue+uniapp 聊天
  17. click延时解决方案
  18. 将形如 5D, 30s 的字符串转为秒
  19. “五一”国际劳动节是怎么来的?
  20. 王小川告别搜狗:卸任CEO职务 爱过,无怨无悔

热门文章

  1. [BZOJ 2734] 集合选数
  2. Ajax(jquery)
  3. “==”和equals()那些事
  4. 修改 wordpress 后台管理员登录地址
  5. 在ubuntu 14.04 编译android 2.3.1 错误解决办法
  6. redis 报 error NOTAUTH Authentication required
  7. 代码执行-preg_replace
  8. [Python爬虫] Selenium自动访问Firefox和Chrome并实现搜索截图
  9. [python知识] 爬虫知识之BeautifulSoup库安装及简单介绍
  10. [Android] 给图像添加相框、圆形圆角显示图片、图像合成知识