#include <iostream> #include <vector> #include <algorithm> using namespace std; const int N = 105; struct S { int p, k, c; }; S s[N]; S tp[N]; bool cmp1(const S& s1, const S& s2) { return s1.p < s2.p; } int cp = 0; int main() { ios_base::sync_with_stdio(false); int n, m, siz = 0; cin >> n >> m; for(int i = 0; i < n; ++i) cin >> s[i].p >> s[i].k >> s[i].c, --s[i].k; sort(s, s+n, cmp1); int i = 0; while(i < n || siz > 0) { if(i < n && cp == s[i].p) { tp[siz++] = s[i++]; continue; } if(siz > 0) { for(int j = 1; j < siz; ++j) { int k = j; S& s1 = tp[k]; S& s2 = tp[k-1]; while(k > 0 && s1.k-s1.c < s2.k-s2.c) { swap(s1, s2); ++k; } } for(int j = 0; j < m && j < siz; ++j) --tp[j].c; ++cp; for(int j = 0; j < siz; ++j) { if(tp[j].c == 0) swap(tp[j], tp[siz-1]), --siz, --j; else if(tp[j].k < cp) { cout << "NIE" << endl; return 0; } } continue; } cp = s[i].p; tp[siz++] = s[i++]; } cout << "TAK" << endl; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; const int N = 105; struct S { int p, k, c; }; S s[N]; S tp[N]; bool cmp1(const S& s1, const S& s2) { return s1.p < s2.p; } int cp = 0; int main() { ios_base::sync_with_stdio(false); int n, m, siz = 0; cin >> n >> m; for(int i = 0; i < n; ++i) cin >> s[i].p >> s[i].k >> s[i].c, --s[i].k; sort(s, s+n, cmp1); int i = 0; while(i < n || siz > 0) { if(i < n && cp == s[i].p) { tp[siz++] = s[i++]; continue; } if(siz > 0) { for(int j = 1; j < siz; ++j) { int k = j; S& s1 = tp[k]; S& s2 = tp[k-1]; while(k > 0 && s1.k-s1.c < s2.k-s2.c) { swap(s1, s2); ++k; } } for(int j = 0; j < m && j < siz; ++j) --tp[j].c; ++cp; for(int j = 0; j < siz; ++j) { if(tp[j].c == 0) swap(tp[j], tp[siz-1]), --siz, --j; else if(tp[j].k < cp) { cout << "NIE" << endl; return 0; } } continue; } cp = s[i].p; tp[siz++] = s[i++]; } cout << "TAK" << endl; return 0; } |