#include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const int N=100010; int Case,n,i,j,tmp,l,a,b;ll e; struct E{int x,y;E(){}E(int _x,int _y){x=_x,y=_y;}}f[N],g[N]; inline bool cmp(const E&a,const E&b){return a.x<b.x;} inline bool solve(){ scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d%d%d",&l,&a,&b); f[i]=E(a,l); g[i]=E(b,l); } sort(f+1,f+n+1,cmp); sort(g+1,g+n+1,cmp); for(i=j=1,e=0;i<=n;i++)while(f[i].y){ while(!g[j].y)j++; tmp=min(f[i].y,g[j].y); f[i].y-=tmp; g[j].y-=tmp; e+=1LL*tmp*(g[j].x-f[i].x); if(e<0)return 0; } return !e; } int main(){ scanf("%d",&Case); while(Case--)puts(solve()?"TAK":"NIE"); }
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 | #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const int N=100010; int Case,n,i,j,tmp,l,a,b;ll e; struct E{int x,y;E(){}E(int _x,int _y){x=_x,y=_y;}}f[N],g[N]; inline bool cmp(const E&a,const E&b){return a.x<b.x;} inline bool solve(){ scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d%d%d",&l,&a,&b); f[i]=E(a,l); g[i]=E(b,l); } sort(f+1,f+n+1,cmp); sort(g+1,g+n+1,cmp); for(i=j=1,e=0;i<=n;i++)while(f[i].y){ while(!g[j].y)j++; tmp=min(f[i].y,g[j].y); f[i].y-=tmp; g[j].y-=tmp; e+=1LL*tmp*(g[j].x-f[i].x); if(e<0)return 0; } return !e; } int main(){ scanf("%d",&Case); while(Case--)puts(solve()?"TAK":"NIE"); } |