#include <cstdio> #include <algorithm> using namespace std; struct task { int p, k, c, skip; inline bool todo(int i) { return c && p <= i && i < k; } }; bool cmp (task i, task j) { return i.skip < j.skip; } int n, m, maxK = 0; task tasks[100]; bool doNow(int i, int j, int procLeft) { int z = 0; for (int k = j + 1; j < n; ++j) { if (tasks[k].todo(i) && ++z >= procLeft) return false; } return true; } int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d %d %d", &tasks[i].p, &tasks[i].k, &tasks[i].c); tasks[i].skip = tasks[i].k - tasks[i].p - tasks[i].c; maxK = max(maxK, tasks[i].k); } sort(tasks, tasks + n, cmp); int done = 0; for (int i = 0; i <= maxK; ++i) { int procUsed = 0; for (int j = 0; j < n; ++j) { if (!tasks[j].todo(i)) { continue; } if (procUsed < m && (tasks[j].skip == 0 || tasks[j].c > 1 || doNow(i, j, m - procUsed))) { procUsed++; tasks[j].c--; if (tasks[j].c == 0) { done++; } } else { tasks[j].skip--; int swapIdx = j; while (swapIdx > 0 && tasks[swapIdx].c && tasks[swapIdx - 1].skip > tasks[j].skip) swapIdx--; swap(tasks[j], tasks[swapIdx]); } } } if (done == n) printf("TAK\n"); else printf("NIE\n"); }
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 | #include <cstdio> #include <algorithm> using namespace std; struct task { int p, k, c, skip; inline bool todo(int i) { return c && p <= i && i < k; } }; bool cmp (task i, task j) { return i.skip < j.skip; } int n, m, maxK = 0; task tasks[100]; bool doNow(int i, int j, int procLeft) { int z = 0; for (int k = j + 1; j < n; ++j) { if (tasks[k].todo(i) && ++z >= procLeft) return false; } return true; } int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d %d %d", &tasks[i].p, &tasks[i].k, &tasks[i].c); tasks[i].skip = tasks[i].k - tasks[i].p - tasks[i].c; maxK = max(maxK, tasks[i].k); } sort(tasks, tasks + n, cmp); int done = 0; for (int i = 0; i <= maxK; ++i) { int procUsed = 0; for (int j = 0; j < n; ++j) { if (!tasks[j].todo(i)) { continue; } if (procUsed < m && (tasks[j].skip == 0 || tasks[j].c > 1 || doNow(i, j, m - procUsed))) { procUsed++; tasks[j].c--; if (tasks[j].c == 0) { done++; } } else { tasks[j].skip--; int swapIdx = j; while (swapIdx > 0 && tasks[swapIdx].c && tasks[swapIdx - 1].skip > tasks[j].skip) swapIdx--; swap(tasks[j], tasks[swapIdx]); } } } if (done == n) printf("TAK\n"); else printf("NIE\n"); } |