#include <bits/stdc++.h> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for (int i=(a); i<(b); ++i) #define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i) #define MAX(dst,src) dst = max(dst, (src)) #define MIN(dst,src) dst = min(dst, (src)) #define pb push_back #define mp make_pair #define st first #define nd second void scase() { int N; scanf("%d", &N); vector<PII> start, goal; REP(i,N) { int l, a, b; scanf("%d%d%d", &l, &a, &b); start.pb({a, l}); goal.pb({b, l}); } sort(start.begin(), start.end()); sort(goal.begin(), goal.end()); LL initial = 0, required = 0; int j = 0; bool ok = true; REP(i,N) { while (goal[i].nd) { if (!start[j].nd) ++j; int k = min(goal[i].nd, start[j].nd); initial += k * (LL)start[j].st; required += k * (LL)goal[i].st; goal[i].nd -= k; start[j].nd -= k; } if (initial > required) ok = false; } ok = ok && (initial == required); printf(ok ? "TAK\n" : "NIE\n"); } int main(int argc, char* argv[]) { int Z; scanf("%d", &Z); while(Z--)scase(); }
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 | #include <bits/stdc++.h> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for (int i=(a); i<(b); ++i) #define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i) #define MAX(dst,src) dst = max(dst, (src)) #define MIN(dst,src) dst = min(dst, (src)) #define pb push_back #define mp make_pair #define st first #define nd second void scase() { int N; scanf("%d", &N); vector<PII> start, goal; REP(i,N) { int l, a, b; scanf("%d%d%d", &l, &a, &b); start.pb({a, l}); goal.pb({b, l}); } sort(start.begin(), start.end()); sort(goal.begin(), goal.end()); LL initial = 0, required = 0; int j = 0; bool ok = true; REP(i,N) { while (goal[i].nd) { if (!start[j].nd) ++j; int k = min(goal[i].nd, start[j].nd); initial += k * (LL)start[j].st; required += k * (LL)goal[i].st; goal[i].nd -= k; start[j].nd -= k; } if (initial > required) ok = false; } ok = ok && (initial == required); printf(ok ? "TAK\n" : "NIE\n"); } int main(int argc, char* argv[]) { int Z; scanf("%d", &Z); while(Z--)scase(); } |