/* * Author: pavveu */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int,int>; using edge = tuple<int,int,int,int>; // weight, id, from, to using graph = vector<vector<edge>>; #define all(x) begin(x), end(x) #define mp make_pair #define mt make_tuple void go() { int n; cin >> n; ll aSum = 0; ll bSum = 0; int aMax = -1; int bMax = -1; bool possible = true; map<int, ll> A, B; for (int i = 0; i < n; i++) { int l, a, b; cin >> l >> a >> b; if ( A.find(a) == A.end() ) A[a] = 0; if ( B.find(b) == B.end() ) B[b] = 0; A[a] += l; B[b] += l; aMax = max(aMax, a); bMax = max(bMax, b); aSum += a * l; bSum += b * l; } if ( aSum != bSum ) possible = false; if ( aMax < bMax ) possible = false; if ( aMax == bMax && A[aMax] < B[bMax] ) possible = false; if ( possible ) cout << "TAK\n"; else cout << "NIE\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) go(); }
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 | /* * Author: pavveu */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int,int>; using edge = tuple<int,int,int,int>; // weight, id, from, to using graph = vector<vector<edge>>; #define all(x) begin(x), end(x) #define mp make_pair #define mt make_tuple void go() { int n; cin >> n; ll aSum = 0; ll bSum = 0; int aMax = -1; int bMax = -1; bool possible = true; map<int, ll> A, B; for (int i = 0; i < n; i++) { int l, a, b; cin >> l >> a >> b; if ( A.find(a) == A.end() ) A[a] = 0; if ( B.find(b) == B.end() ) B[b] = 0; A[a] += l; B[b] += l; aMax = max(aMax, a); bMax = max(bMax, b); aSum += a * l; bSum += b * l; } if ( aSum != bSum ) possible = false; if ( aMax < bMax ) possible = false; if ( aMax == bMax && A[aMax] < B[bMax] ) possible = false; if ( possible ) cout << "TAK\n"; else cout << "NIE\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) go(); } |