#include <bits/stdc++.h> using namespace std; int main() { int T; scanf("%d", &T); while (T--) { int N; scanf("%d", &N); vector<pair<int, int>> va, vb; for (int i = 1; i <= N; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); va.push_back({b, a}); vb.push_back({c, a}); } sort(va.begin(), va.end()); sort(vb.begin(), vb.end()); vector<pair<long long, int>> momenty; long long chwila = 0; for (auto it : va) { momenty.push_back({chwila, it.first}); chwila += it.second; } momenty.push_back({chwila, 0}); chwila = 0; for (auto it : vb) { momenty.push_back({chwila, -it.first}); chwila += it.second; } sort(momenty.begin(), momenty.end()); chwila = 0; int currA = 0, currB = 0; long long sum = 0; bool kk = true; for (auto it : momenty) { sum += (currB - currA) * (it.first - chwila); if (it.second < 0) currB = -it.second; else currA = it.second; chwila = it.first; if (sum < 0) kk = false; } kk &= sum == 0; printf(kk ? "TAK\n" : "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 | #include <bits/stdc++.h> using namespace std; int main() { int T; scanf("%d", &T); while (T--) { int N; scanf("%d", &N); vector<pair<int, int>> va, vb; for (int i = 1; i <= N; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); va.push_back({b, a}); vb.push_back({c, a}); } sort(va.begin(), va.end()); sort(vb.begin(), vb.end()); vector<pair<long long, int>> momenty; long long chwila = 0; for (auto it : va) { momenty.push_back({chwila, it.first}); chwila += it.second; } momenty.push_back({chwila, 0}); chwila = 0; for (auto it : vb) { momenty.push_back({chwila, -it.first}); chwila += it.second; } sort(momenty.begin(), momenty.end()); chwila = 0; int currA = 0, currB = 0; long long sum = 0; bool kk = true; for (auto it : momenty) { sum += (currB - currA) * (it.first - chwila); if (it.second < 0) currB = -it.second; else currA = it.second; chwila = it.first; if (sum < 0) kk = false; } kk &= sum == 0; printf(kk ? "TAK\n" : "NIE\n"); } return 0; } |