#pragma GCC optimize("Ofast")
#include <iostream>
#include <algorithm>
using namespace std;
int t,n,l,a[1000001],b[1000001],w,tempa[1000001],tempb[1000001];
long long l1,l2,m;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--)
{
cin>>n;
for(int i=0; i<n; i++)
{
cin>>l>>a[i]>>b[i];
l1+=a[i]*l;
tempa[a[i]]+=l;
l2+=b[i]*l;
tempb[b[i]]+=l;
m+=l;
}
if(l1==l2)
w++;
sort(a,a+n);
sort(b,b+n);
if(tempa[a[0]]>=tempb[a[0]])
w++;
if(tempa[a[n-1]]>=tempb[a[n-1]])
w++;
if(a[0]<=b[0])
w++;
if(a[n-1]>=b[n-1])
w++;
if(w==5)
cout<<"TAK"<<'\n';
else
cout<<"NIE"<<'\n';
l1=0;
l2=0;
m=0;
w=0;
}
return 0;
}
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 | #pragma GCC optimize("Ofast") #include <iostream> #include <algorithm> using namespace std; int t,n,l,a[1000001],b[1000001],w,tempa[1000001],tempb[1000001]; long long l1,l2,m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>t; while(t--) { cin>>n; for(int i=0; i<n; i++) { cin>>l>>a[i]>>b[i]; l1+=a[i]*l; tempa[a[i]]+=l; l2+=b[i]*l; tempb[b[i]]+=l; m+=l; } if(l1==l2) w++; sort(a,a+n); sort(b,b+n); if(tempa[a[0]]>=tempb[a[0]]) w++; if(tempa[a[n-1]]>=tempb[a[n-1]]) w++; if(a[0]<=b[0]) w++; if(a[n-1]>=b[n-1]) w++; if(w==5) cout<<"TAK"<<'\n'; else cout<<"NIE"<<'\n'; l1=0; l2=0; m=0; w=0; } return 0; } |
English