#include <cstdio> #include <vector> #include <algorithm> using namespace std; struct task { public: int start, end, length; }; class Comparator { public: bool operator()(task a, task b) { return (a.end - a.length) < (b.end - b.length); } } c; int main() { vector<task> v; int n, m; scanf("%d%d", &n, &m); int s, e, l; task t; v.reserve(n); int* busy = new int[101](); for (int i = 0; i < n; i++) { scanf("%d%d%d", &t.start, &t.end, &t.length); v.push_back(t); } sort(v.begin(), v.end(), c); for (int i = 0; i < n; i++) { bool success = false; for (int p = 0; p < m; p++) { if (busy[p] <= (v[i].end-v[i].length)) { success = true; busy[p] = busy[p] + v[i].length; break; } } if (!success) { printf("NIE\n"); return 0; } } printf("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 | #include <cstdio> #include <vector> #include <algorithm> using namespace std; struct task { public: int start, end, length; }; class Comparator { public: bool operator()(task a, task b) { return (a.end - a.length) < (b.end - b.length); } } c; int main() { vector<task> v; int n, m; scanf("%d%d", &n, &m); int s, e, l; task t; v.reserve(n); int* busy = new int[101](); for (int i = 0; i < n; i++) { scanf("%d%d%d", &t.start, &t.end, &t.length); v.push_back(t); } sort(v.begin(), v.end(), c); for (int i = 0; i < n; i++) { bool success = false; for (int p = 0; p < m; p++) { if (busy[p] <= (v[i].end-v[i].length)) { success = true; busy[p] = busy[p] + v[i].length; break; } } if (!success) { printf("NIE\n"); return 0; } } printf("TAK\n"); return 0; } |