#include <bits/stdc++.h>
using namespace std;
long long a,b,p,n,t,w,v,dost,pot,x;
bool test,u;
vector <pair <long long,long long> > kubki;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
for(int i=0; i<t; i++){
cin >> n;
dost=0,pot=0,w=0,x=0,v=0;
test=false;
while(!kubki.empty()){
kubki.pop_back();
}
for(int j=0; j<n; j++){
cin >> p >> a >> b;
dost+=p*a;
pot+=p*b;
kubki.push_back(make_pair(a,p));
kubki.push_back(make_pair(b,-p));
}
sort(kubki.begin(),kubki.end());
//cout << endl;
for(int j=0; j<kubki.size(); j++){
x=kubki[j].first*kubki[j].second;
if(abs(v*kubki[j].first)>abs(w) && x>=0 && v<=0) test=true;
w+=x;
v+=kubki[j].second;
}
if(dost==pot && test==false) cout << "TAK" << '\n';
else cout << "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 | #include <bits/stdc++.h> using namespace std; long long a,b,p,n,t,w,v,dost,pot,x; bool test,u; vector <pair <long long,long long> > kubki; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> t; for(int i=0; i<t; i++){ cin >> n; dost=0,pot=0,w=0,x=0,v=0; test=false; while(!kubki.empty()){ kubki.pop_back(); } for(int j=0; j<n; j++){ cin >> p >> a >> b; dost+=p*a; pot+=p*b; kubki.push_back(make_pair(a,p)); kubki.push_back(make_pair(b,-p)); } sort(kubki.begin(),kubki.end()); //cout << endl; for(int j=0; j<kubki.size(); j++){ x=kubki[j].first*kubki[j].second; if(abs(v*kubki[j].first)>abs(w) && x>=0 && v<=0) test=true; w+=x; v+=kubki[j].second; } if(dost==pot && test==false) cout << "TAK" << '\n'; else cout << "NIE" << '\n'; } } |
English