#include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define ui unsigned int #define inf 1000000000 #define INF 1000000000000000000LL #define VI vector<int> #define VLL vector<ll> #define PII pair<int, int> #define st first #define nd second #define pb push_back #define mp make_pair #define eb emplace_back #define endl '\n' #define REP(x, y) for(int x = 0; x < (y); ++x) #define FOR(x, y, z) for(int x = y; x <= (z); ++x) using namespace std; int n, m, mint = inf, maxt; int p[107]; int k[107]; int c[107]; VI s[1000007]; VI z; inline bool comp(int a, int b) { return c[a]-k[a]>c[b]-k[b]; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> m; for(int i = 1; i <= n; ++i) { cin >> p[i] >> k[i] >> c[i]; ++p[i]; s[p[i]].pb(i); mint = min(mint, p[i]); maxt = max(maxt, k[i]); } for(int t = mint; t <= maxt; ++t) { z.insert(z.end(), s[t].begin(), s[t].end()); sort(z.begin(), z.end(), comp); for(int i = 0; i < z.size(); ++i) { if(i<m) { --c[z[i]]; } } for(int i = 0; i < z.size(); ++i) { if(c[z[i]]==0) { swap(z[i], z.back()); z.pop_back(); --i; continue; } if(k[z[i]]==t && c[z[i]]>0) { cout << "NIE"; return 0; } } } cout << "TAK"; }
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 | #include<bits/stdc++.h> #define ll long long #define ull unsigned long long #define ui unsigned int #define inf 1000000000 #define INF 1000000000000000000LL #define VI vector<int> #define VLL vector<ll> #define PII pair<int, int> #define st first #define nd second #define pb push_back #define mp make_pair #define eb emplace_back #define endl '\n' #define REP(x, y) for(int x = 0; x < (y); ++x) #define FOR(x, y, z) for(int x = y; x <= (z); ++x) using namespace std; int n, m, mint = inf, maxt; int p[107]; int k[107]; int c[107]; VI s[1000007]; VI z; inline bool comp(int a, int b) { return c[a]-k[a]>c[b]-k[b]; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> m; for(int i = 1; i <= n; ++i) { cin >> p[i] >> k[i] >> c[i]; ++p[i]; s[p[i]].pb(i); mint = min(mint, p[i]); maxt = max(maxt, k[i]); } for(int t = mint; t <= maxt; ++t) { z.insert(z.end(), s[t].begin(), s[t].end()); sort(z.begin(), z.end(), comp); for(int i = 0; i < z.size(); ++i) { if(i<m) { --c[z[i]]; } } for(int i = 0; i < z.size(); ++i) { if(c[z[i]]==0) { swap(z[i], z.back()); z.pop_back(); --i; continue; } if(k[z[i]]==t && c[z[i]]>0) { cout << "NIE"; return 0; } } } cout << "TAK"; } |