// VSCF.cpp : Defines the entry point for the console application. // #include <random> #include <climits> #include <queue> #include <bitset> #include <cassert> #include <functional> #include <cmath> #include <list> #include <cstdio> #include <iostream> #include <algorithm> #include <iterator> #include <string> #include <vector> #include <set> #include <deque> #include <map> #include <iomanip> #include <sstream> using namespace std; #define int long long typedef long long LL; typedef pair<int, int> PII; #define MP make_pair #define FOR(v,p,k) for(int v=p;v<=k;++v) #define FORD(v,p,k) for(int v=p;v>=k;--v) #define REP(i,n) for(int i=0;i<(n);++i) #define VAR(v,i) decltype(i) v=(i) #define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i) #define PB push_back #define ST first #define ND second #define SIZE(x) (int)x.size() #define ALL(c) c.begin(),c.end() #define MAXN 1000010 typedef long double LD; typedef vector<int> VI; struct task { int p, k, c; }; bool operator<(const task& t1, const task& t2) { return tie(t1.p, t1.k, t1.c) < tie(t2.p, t2.k, t2.c); } #undef int int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; int MX = 1e6 + 1; vector<PII> rem(MX); vector<task> t; REP(i, n) { int p, k, c; cin >> p >> k >> c; t.push_back({ p, k, c }); } vector<PII> toDo; sort(ALL(t)); reverse(ALL(t)); REP(i, MX) { int added = 0; while (!t.empty() && t.back().p == i) { toDo.push_back(MP(t.back().k, t.back().c)); t.pop_back(); } sort(ALL(toDo), [&](const PII & lh, const PII & rh) {return lh.first - i - lh.second < rh.first - i - rh.second; }); int s = toDo.size(); int proc = m; REP(j, s) { if (toDo[j].first <= i) { if (toDo[j].second) { cout << "NIE\n"; return 0; } } else { if (toDo[j].second) { toDo[j].second--; proc--; if (!proc) { break; } } } } } cout << "TAK\n"; 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 | // VSCF.cpp : Defines the entry point for the console application. // #include <random> #include <climits> #include <queue> #include <bitset> #include <cassert> #include <functional> #include <cmath> #include <list> #include <cstdio> #include <iostream> #include <algorithm> #include <iterator> #include <string> #include <vector> #include <set> #include <deque> #include <map> #include <iomanip> #include <sstream> using namespace std; #define int long long typedef long long LL; typedef pair<int, int> PII; #define MP make_pair #define FOR(v,p,k) for(int v=p;v<=k;++v) #define FORD(v,p,k) for(int v=p;v>=k;--v) #define REP(i,n) for(int i=0;i<(n);++i) #define VAR(v,i) decltype(i) v=(i) #define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i) #define PB push_back #define ST first #define ND second #define SIZE(x) (int)x.size() #define ALL(c) c.begin(),c.end() #define MAXN 1000010 typedef long double LD; typedef vector<int> VI; struct task { int p, k, c; }; bool operator<(const task& t1, const task& t2) { return tie(t1.p, t1.k, t1.c) < tie(t2.p, t2.k, t2.c); } #undef int int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; int MX = 1e6 + 1; vector<PII> rem(MX); vector<task> t; REP(i, n) { int p, k, c; cin >> p >> k >> c; t.push_back({ p, k, c }); } vector<PII> toDo; sort(ALL(t)); reverse(ALL(t)); REP(i, MX) { int added = 0; while (!t.empty() && t.back().p == i) { toDo.push_back(MP(t.back().k, t.back().c)); t.pop_back(); } sort(ALL(toDo), [&](const PII & lh, const PII & rh) {return lh.first - i - lh.second < rh.first - i - rh.second; }); int s = toDo.size(); int proc = m; REP(j, s) { if (toDo[j].first <= i) { if (toDo[j].second) { cout << "NIE\n"; return 0; } } else { if (toDo[j].second) { toDo[j].second--; proc--; if (!proc) { break; } } } } } cout << "TAK\n"; return 0; } |