#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxN = 1e6 + 10; int N; void prog() { vector<pair<int, int>> events; scanf("%d", &N); for (int M, t1, t2, i = 0; i < N; ++i) { scanf("%d%d%d", &M, &t1, &t2); events.emplace_back(t1, M); events.emplace_back(t2, -M); } sort(events.begin(), events.end()); ll change = events.back().second, total = 0; for (int i = events.size() - 2; i >= 0; --i) { total += change * (events[i + 1].first - events[i].first); change += events[i].second; if (total < 0) { puts("NIE"); return; } } if (total) puts("NIE"); else puts("TAK"); } int main() { int z; scanf("%d", &z); while (z--) prog(); }
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 | #include <bits/stdc++.h> using namespace std; using ll = long long; const int maxN = 1e6 + 10; int N; void prog() { vector<pair<int, int>> events; scanf("%d", &N); for (int M, t1, t2, i = 0; i < N; ++i) { scanf("%d%d%d", &M, &t1, &t2); events.emplace_back(t1, M); events.emplace_back(t2, -M); } sort(events.begin(), events.end()); ll change = events.back().second, total = 0; for (int i = events.size() - 2; i >= 0; --i) { total += change * (events[i + 1].first - events[i].first); change += events[i].second; if (total < 0) { puts("NIE"); return; } } if (total) puts("NIE"); else puts("TAK"); } int main() { int z; scanf("%d", &z); while (z--) prog(); } |