#include<bits/stdc++.h> using namespace std; #define int long long void run(){ int n,sa=0,sb=0; cin >>n; deque<pair<int,int> > qa,qb; for(int i=0;i<n;i++){ int l,a,b; cin >>l >>a >>b; sa+=a*l; sb+=b*l; qa.push_back({a,l}); qb.push_back({b,l}); } if(sa!=sb){ cout <<"NIE\n"; return; } sa=0; sb=0; sort(qa.begin(),qa.end()); sort(qb.begin(),qb.end()); while(qa.size() && qb.size()){ int here=min(qa[0].second,qb[0].second); sa+=here*qa[0].first; sb+=here*qb[0].first; qa[0].second-=here; qb[0].second-=here; if(qa[0].second==0)qa.pop_front(); if(qb[0].second==0)qb.pop_front(); if(sa>sb){ cout <<"NIE\n"; return; } } cout <<"TAK\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); int z; cin >>z; while(z--){ run(); } }
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 | #include<bits/stdc++.h> using namespace std; #define int long long void run(){ int n,sa=0,sb=0; cin >>n; deque<pair<int,int> > qa,qb; for(int i=0;i<n;i++){ int l,a,b; cin >>l >>a >>b; sa+=a*l; sb+=b*l; qa.push_back({a,l}); qb.push_back({b,l}); } if(sa!=sb){ cout <<"NIE\n"; return; } sa=0; sb=0; sort(qa.begin(),qa.end()); sort(qb.begin(),qb.end()); while(qa.size() && qb.size()){ int here=min(qa[0].second,qb[0].second); sa+=here*qa[0].first; sb+=here*qb[0].first; qa[0].second-=here; qb[0].second-=here; if(qa[0].second==0)qa.pop_front(); if(qb[0].second==0)qb.pop_front(); if(sa>sb){ cout <<"NIE\n"; return; } } cout <<"TAK\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); int z; cin >>z; while(z--){ run(); } } |