#include <iostream> #include <algorithm> #include <queue> using namespace std; int n, m; struct proces { ; int p; int k; int c; }; const int K = 1000001; const int N = 101; bool tab[K][N]; int countt[K]; proces process[N]; int main() { ios_base::sync_with_stdio(0); cin >> n >> m; int maxK = 0; for (int i = 0; i < n; i++) { cin >> process[i].p >> process[i].k >> process[i].c; maxK = max(maxK, process[i].k); } for (int i = 0; i < n; i++) { for (int j = process[i].p; j < process[i].k; j++) { tab[j][i] = true; countt[j]++; } } int done = 0; for (int i = 0; i <= maxK; i++) { if (countt[i] <= m) { for (int j = 0; j < n; j++) { if (tab[i][j]) { process[j].c--; process[j].k--; if (process[j].c == 0) { done++; } } } } } int key, id; for (int t = 0; t < maxK; t++) { if (countt[t] > m) { priority_queue<pair<int, int>> Q; for (int i = 0; i < n; i++) { if (tab[t][i] && process[i].c > 0) { process[i].k--; key = -(process[i].k - process[i].c - process[i].p); Q.push(make_pair(key, i)); } } for (int i = 0; i < m && !Q.empty(); i++) { id = Q.top().second; Q.pop(); process[id].c--; if (process[id].c == 0) { done++; } } } } if (done < n) { cout << "NIE"; } else { cout << "TAK"; } return 0; }
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 95 96 97 98 99 100 101 102 103 104 105 106 | #include <iostream> #include <algorithm> #include <queue> using namespace std; int n, m; struct proces { ; int p; int k; int c; }; const int K = 1000001; const int N = 101; bool tab[K][N]; int countt[K]; proces process[N]; int main() { ios_base::sync_with_stdio(0); cin >> n >> m; int maxK = 0; for (int i = 0; i < n; i++) { cin >> process[i].p >> process[i].k >> process[i].c; maxK = max(maxK, process[i].k); } for (int i = 0; i < n; i++) { for (int j = process[i].p; j < process[i].k; j++) { tab[j][i] = true; countt[j]++; } } int done = 0; for (int i = 0; i <= maxK; i++) { if (countt[i] <= m) { for (int j = 0; j < n; j++) { if (tab[i][j]) { process[j].c--; process[j].k--; if (process[j].c == 0) { done++; } } } } } int key, id; for (int t = 0; t < maxK; t++) { if (countt[t] > m) { priority_queue<pair<int, int>> Q; for (int i = 0; i < n; i++) { if (tab[t][i] && process[i].c > 0) { process[i].k--; key = -(process[i].k - process[i].c - process[i].p); Q.push(make_pair(key, i)); } } for (int i = 0; i < m && !Q.empty(); i++) { id = Q.top().second; Q.pop(); process[id].c--; if (process[id].c == 0) { done++; } } } } if (done < n) { cout << "NIE"; } else { cout << "TAK"; } return 0; } |