#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
int t;
cin>>t;
for(int tt=0;tt<t;tt++)
{
//int min1=0,min2=0,max1=0,max2=0;
int n;
cin>>n;
vector<pair<int,int>> d;
for(int i=0;i<n;i++)
{
int a,b,c;
cin>>a>>b>>c;
d.push_back(make_pair(b,a));
d.push_back(make_pair(c,-a));
}
sort(d.begin(),d.end());
int poz=d.size();
while(poz>=1)
{
if(d[poz].first==d[poz-1].first)
{
d[poz-1].second+=d[poz].second;
d[poz].first=1000005;
}
poz--;
}
sort(d.begin(),d.end());
while(d[d.size()-1].first==1000005)
{
d.pop_back();
}
if(d.size()==0)
{
cout<<"TAK\n";
continue;
}
if(d[0].second<0||d[d.size()-1].second<0)
{
cout<<"NIE\n";
continue;
}
unsigned long long a=0;
poz=0;
while(poz<d.size())
{
a+=d[poz].first*d[poz].second;
poz++;
}
if(a!=0){
cout<<"NIE\n";
continue;
}
cout<<"TAK\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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int t; cin>>t; for(int tt=0;tt<t;tt++) { //int min1=0,min2=0,max1=0,max2=0; int n; cin>>n; vector<pair<int,int>> d; for(int i=0;i<n;i++) { int a,b,c; cin>>a>>b>>c; d.push_back(make_pair(b,a)); d.push_back(make_pair(c,-a)); } sort(d.begin(),d.end()); int poz=d.size(); while(poz>=1) { if(d[poz].first==d[poz-1].first) { d[poz-1].second+=d[poz].second; d[poz].first=1000005; } poz--; } sort(d.begin(),d.end()); while(d[d.size()-1].first==1000005) { d.pop_back(); } if(d.size()==0) { cout<<"TAK\n"; continue; } if(d[0].second<0||d[d.size()-1].second<0) { cout<<"NIE\n"; continue; } unsigned long long a=0; poz=0; while(poz<d.size()) { a+=d[poz].first*d[poz].second; poz++; } if(a!=0){ cout<<"NIE\n"; continue; } cout<<"TAK\n"; } } |
English