1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include <bits/stdc++.h> using namespace std;
const int N = 1e5 + 66;
int n, i, j, k, pd, res; int me[7], a[N][7], b[N][7], vis[N];
struct yhzhyhm { int f, g; bool operator < (const yhzhyhm &x) const { return f < x.f; } }yh[N];
inline void yhm_clear() { res = 0; memset(me, 0, sizeof me); memset(a, 0, sizeof a); memset(b, 0, sizeof b); memset(vis, 0, sizeof vis); memset(&yh, 0, sizeof yh); return; }
inline void yh_func() { me[1] = read(); for (i = 1; i <= n; ++ i) yh[i].f = read(), yh[i].g = read(); sort(yh + 1, yh + 1 + n); for (i = 1; i <= n; ++ i) { if (me[1] >= yh[i].f) { me[1] += yh[i].g; ++ res; } }
put(res), put(me[1]);
return; }
inline void yhm_func() { n = read(), k = read(); if (k == 1) return (void)(yh_func()); for (i = 1; i <= k; ++ i) me[i] = read(); for (i = 1; i <= n; ++ i) { int num = 0; for (j = 1; j <= k; ++ j) a[i][j] = read(); for (j = 1; j <= k; ++ j) b[i][j] = read(); }
do{ pd = 0; for (i = 1; i <= n; ++ i) { if (vis[i]) continue; int num = 0; for (j = 1; j <= k; ++ j) if (me[j] >= a[i][j]) ++ num; if (num == k) { for (j = 1; j <= k; ++ j) me[j] += b[i][j]; ++ res; vis[i] = 1; pd = 1; } } }while (pd == 1);
put(res); for (i = 1; i <= k; ++ i) putf(me[i]); puts(""); return; }
signed main() { int T = read();
while (T --) { yhm_clear(); yhm_func(); } return 0; }
|