#include <iostream>
using namespace std;
int main() {
int t;
long long l, a, b, balance;
int n, lowest_a, highest_a, lowest_b, highest_b;
cin>>t;
for(int i = 0; i < t; i++){
balance = 0;
lowest_a = 10000000;
highest_a = -1;
lowest_b = 10000000;
highest_b = -1;
cin>>n;
for(int j = 0; j < n; j++){
cin>>l>>a>>b;
balance += l*a;
balance -= l*b;
if(a < lowest_a){
lowest_a = a;
}
if(a > highest_a){
highest_a = a;
}
if(b < lowest_b){
lowest_b = b;
}
if(b > highest_b){
highest_b = b;
}
}
if(balance == 0 && (lowest_a <= lowest_b) && (highest_a >= highest_b)){
cout<<"TAK"<<endl;
}
else{
cout<<"NIE"<<endl;
}
}
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 51 52 | #include <iostream> using namespace std; int main() { int t; long long l, a, b, balance; int n, lowest_a, highest_a, lowest_b, highest_b; cin>>t; for(int i = 0; i < t; i++){ balance = 0; lowest_a = 10000000; highest_a = -1; lowest_b = 10000000; highest_b = -1; cin>>n; for(int j = 0; j < n; j++){ cin>>l>>a>>b; balance += l*a; balance -= l*b; if(a < lowest_a){ lowest_a = a; } if(a > highest_a){ highest_a = a; } if(b < lowest_b){ lowest_b = b; } if(b > highest_b){ highest_b = b; } } if(balance == 0 && (lowest_a <= lowest_b) && (highest_a >= highest_b)){ cout<<"TAK"<<endl; } else{ cout<<"NIE"<<endl; } } return 0; } |
English