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
| #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 1, M = 1e5 + 1, T = 1e6 + 1; struct node { int a, b, c; friend bool operator<(node a, node b) { return a.a < b.a; } } t[N]; int n, q, f[M]; struct nod { int m, k, s, id; friend bool operator<(nod a, nod b) { return a.m < b.m; } } a[T]; bool ff[T]; int main() { cin >> n; int ma = 0; for (int i = 1; i <= n; i++) { scanf("%d%d%d", &t[i].c, &t[i].a, &t[i].b); ma += t[i].c; } ma = min(ma, M - 1); sort(t + 1, t + 1 + n); cin >> q; for (int i = 1; i <= q; i++) { scanf("%d%d%d", &a[i].m, &a[i].k, &a[i].s); a[i].id = i; } sort(a + 1, a + 1 + q); int k = 1; for (int i = 1; i <= n && k <= q; i++) { while (t[i].a > a[k].m && k <= q) { if (f[a[k].k] > a[k].m + a[k].s) ff[a[k].id] = true; k++; } for (int j = ma; j; j--) { if (j > t[i].c) f[j] = max(f[j], min(f[j - t[i].c], t[i].b)); else if (j == t[i].c) f[j] = max(f[j], t[i].b); }
} while (k <= q) { if (f[a[k].k] > a[k].m + a[k].s) ff[a[k].id] = true; k++; } for (int i = 1; i <= q; i++) { if (ff[i]) printf("TAK\n"); else printf("NIE\n"); } return 0; }
|