#include <algorithm> #include <iostream> using namespace std; const int MAX = 128; int n,m; struct zad { int p; int k; int c; }; bool operator < (const zad& a, const zad& b) { return a.k-a.p-a.c < b.k-b.p-b.c; } zad Z[MAX]; int main() { int i; cin>>n>>m; for (i=0; i<n; ++i) { cin>>Z[i].p>>Z[i].k>>Z[i].c; } bool ret_val = true; while (n>0) { sort(Z, Z+n); if (Z[0].k-Z[0].p-Z[0].c < 0) { ret_val = false; break; } int new_time = 1000000+15; for (i=0; i<n; ++i) { if (Z[i].p < new_time) new_time = Z[i].p; } int m2 = m; for (i=0; i<n; ++i) { if (Z[i].p == new_time) { Z[i].p += 1; if (m2 > 0) { Z[i].c -= 1; if (Z[i].c <= 0) { swap(Z[i], Z[n-1]); --n; --i; } --m2; } } } } cout << (ret_val ? "TAK" : "NIE") << endl; }
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 | #include <algorithm> #include <iostream> using namespace std; const int MAX = 128; int n,m; struct zad { int p; int k; int c; }; bool operator < (const zad& a, const zad& b) { return a.k-a.p-a.c < b.k-b.p-b.c; } zad Z[MAX]; int main() { int i; cin>>n>>m; for (i=0; i<n; ++i) { cin>>Z[i].p>>Z[i].k>>Z[i].c; } bool ret_val = true; while (n>0) { sort(Z, Z+n); if (Z[0].k-Z[0].p-Z[0].c < 0) { ret_val = false; break; } int new_time = 1000000+15; for (i=0; i<n; ++i) { if (Z[i].p < new_time) new_time = Z[i].p; } int m2 = m; for (i=0; i<n; ++i) { if (Z[i].p == new_time) { Z[i].p += 1; if (m2 > 0) { Z[i].c -= 1; if (Z[i].c <= 0) { swap(Z[i], Z[n-1]); --n; --i; } --m2; } } } } cout << (ret_val ? "TAK" : "NIE") << endl; } |