#include <bits/stdc++.h> using namespace std; bool check(const vector<pair<int, int>>& vec) { int cur = 0; int64_t mass = 0; int64_t energy = 0; for (const auto& p : vec) { energy += mass * (p.first - cur); cur = p.first; mass += p.second; if (energy < 0) return false; } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t; cin >> t; while (t--) { int n, l, a, b; cin >> n; vector<pair<int, int>> vec; int64_t crc = 0; while (n--) { cin >> l >> a >> b; vec.emplace_back(a, l); vec.emplace_back(b, -l); crc += l * int64_t(b - a); } sort(begin(vec), end(vec)); bool ok = (crc == 0 && check(vec)); cout << (ok ? "TAK\n" : "NIE\n"); } }
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 | #include <bits/stdc++.h> using namespace std; bool check(const vector<pair<int, int>>& vec) { int cur = 0; int64_t mass = 0; int64_t energy = 0; for (const auto& p : vec) { energy += mass * (p.first - cur); cur = p.first; mass += p.second; if (energy < 0) return false; } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t; cin >> t; while (t--) { int n, l, a, b; cin >> n; vector<pair<int, int>> vec; int64_t crc = 0; while (n--) { cin >> l >> a >> b; vec.emplace_back(a, l); vec.emplace_back(b, -l); crc += l * int64_t(b - a); } sort(begin(vec), end(vec)); bool ok = (crc == 0 && check(vec)); cout << (ok ? "TAK\n" : "NIE\n"); } } |