#include <bits/stdc++.h> using namespace std; bool solve(int n, vector <int> &vol, vector <int> &startTemp, vector <int> &targetTemp) { vector <pair<int,int>> events; for (int i = 0; i < n; i++) { events.push_back({startTemp[i], vol[i]}); events.push_back({targetTemp[i], -vol[i]}); } sort(events.begin(), events.end()); int lastTemp = 0; long long accVolume = 0; long long needEnergy = 0; for (auto &e : events) { needEnergy += accVolume * (e.first - lastTemp); lastTemp = e.first; if (needEnergy < 0) { return false; } accVolume += e.second; } return needEnergy == 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector <int> vol(n), startTemp(n), targetTemp(n); for (int i = 0; i < n; i++) { cin >> vol[i] >> startTemp[i] >> targetTemp[i]; } if (solve(n, vol, startTemp, targetTemp)) { cout << "TAK\n"; } else { cout << "NIE\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 | #include <bits/stdc++.h> using namespace std; bool solve(int n, vector <int> &vol, vector <int> &startTemp, vector <int> &targetTemp) { vector <pair<int,int>> events; for (int i = 0; i < n; i++) { events.push_back({startTemp[i], vol[i]}); events.push_back({targetTemp[i], -vol[i]}); } sort(events.begin(), events.end()); int lastTemp = 0; long long accVolume = 0; long long needEnergy = 0; for (auto &e : events) { needEnergy += accVolume * (e.first - lastTemp); lastTemp = e.first; if (needEnergy < 0) { return false; } accVolume += e.second; } return needEnergy == 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector <int> vol(n), startTemp(n), targetTemp(n); for (int i = 0; i < n; i++) { cin >> vol[i] >> startTemp[i] >> targetTemp[i]; } if (solve(n, vol, startTemp, targetTemp)) { cout << "TAK\n"; } else { cout << "NIE\n"; } } return 0; } |