#include <bits/stdc++.h> #define ss second #define ff first using namespace std; priority_queue<pair<long long,long long> > ein; priority_queue<pair<long long,long long> > eout; int main() { long long z,n,a,b,c; long long r,t1,t2; bool q; scanf("%lld", &z); for(int u=0; u<z; u++){ //cout<<u<<endl; //cout<<ein.size()<<" "<<eout.size()<<endl; while(!ein.empty()){ //cout<<ein.size()<<endl; ein.pop(); } while(!eout.empty()){ eout.pop(); } //cout<<u<<endl; scanf("%lld", &n); r=0; q=0; t1=0; t2=0; for(int i=0; i<n; i++){ scanf("%lld%lld%lld", &a, &b, &c); ein.push(make_pair(b,a)); eout.push(make_pair(c,a)); } while(!(ein.empty()||eout.empty())){ //cout<<"a"<<endl; if(ein.top().ss-t2>=eout.top().ss-t1){ r+=(ein.top().ff-eout.top().ff)*(eout.top().ss-t1); t2+=(eout.top().ss-t1); t1=0; eout.pop(); }else{ r+=(ein.top().ff-eout.top().ff)*(ein.top().ss-t2); t1+=ein.top().ss-t2; t2=0; ein.pop(); } //cout<<ein.size()<<" "<<eout.size()<<" "<<r<<" "<<t1<<" "<<t2<<endl; if(r<0){ printf("NIE\n"); q=1; break; } } if(!q){ if(r==0&&((ein.size()==1&&ein.top().ss==t2)||(eout.size()==1&&eout.top().ss==t1))){ printf("TAK\n"); }else{ printf("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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <bits/stdc++.h> #define ss second #define ff first using namespace std; priority_queue<pair<long long,long long> > ein; priority_queue<pair<long long,long long> > eout; int main() { long long z,n,a,b,c; long long r,t1,t2; bool q; scanf("%lld", &z); for(int u=0; u<z; u++){ //cout<<u<<endl; //cout<<ein.size()<<" "<<eout.size()<<endl; while(!ein.empty()){ //cout<<ein.size()<<endl; ein.pop(); } while(!eout.empty()){ eout.pop(); } //cout<<u<<endl; scanf("%lld", &n); r=0; q=0; t1=0; t2=0; for(int i=0; i<n; i++){ scanf("%lld%lld%lld", &a, &b, &c); ein.push(make_pair(b,a)); eout.push(make_pair(c,a)); } while(!(ein.empty()||eout.empty())){ //cout<<"a"<<endl; if(ein.top().ss-t2>=eout.top().ss-t1){ r+=(ein.top().ff-eout.top().ff)*(eout.top().ss-t1); t2+=(eout.top().ss-t1); t1=0; eout.pop(); }else{ r+=(ein.top().ff-eout.top().ff)*(ein.top().ss-t2); t1+=ein.top().ss-t2; t2=0; ein.pop(); } //cout<<ein.size()<<" "<<eout.size()<<" "<<r<<" "<<t1<<" "<<t2<<endl; if(r<0){ printf("NIE\n"); q=1; break; } } if(!q){ if(r==0&&((ein.size()==1&&ein.top().ss==t2)||(eout.size()==1&&eout.top().ss==t1))){ printf("TAK\n"); }else{ printf("NIE\n"); } } } } |