#include <bits/stdc++.h>
using namespace std;
#define nd second
int l[10000 + 5];
int a[10000 + 5];
int b[10000 + 5];
pair<int,int> pom[100000 + 5];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int miniA=1e9;
int maxiA = 0;
int miniB = 1e9;
int maxiB = 0;
for(int i = 1; i <= n; i++){
cin >> l[i] >> a[i] >> b[i];
pom[i] = {a[i],i};
miniA = min(miniA,a[i]);
miniA = min(miniB,b[i]);
maxiA = max(maxiA,a[i]);
maxiB = max(maxiB,b[i]);
}
if(miniB < miniA || maxiB > maxiA){
cout << "NIE" << '\n';
continue;
}
long long sumA = 0,sumB = 0;
sort(pom + 1, pom + n + 1);
bool nie = 0;
int temp = pom[1].nd;
if(a[temp] > b[temp]){
cout << "NIE" << '\n';
continue;
}
for(int i = 1; i <= n; i++){
int id = pom[i].nd;
int tA = a[id];
int tB = b[id];
int litr = l[id];
sumA += litr * tA;
sumB += litr * tB;
if(sumA > sumB){
cout << "NIE" << '\n';
nie = 1;
break;
}
}
if(sumA != sumB)
cout << "NIE" << '\n';
else if(!nie)
cout << "TAK" << '\n';
}
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 53 54 55 56 57 58 59 60 61 62 63 64 | #include <bits/stdc++.h> using namespace std; #define nd second int l[10000 + 5]; int a[10000 + 5]; int b[10000 + 5]; pair<int,int> pom[100000 + 5]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t; cin >> t; while(t--){ int n; cin >> n; int miniA=1e9; int maxiA = 0; int miniB = 1e9; int maxiB = 0; for(int i = 1; i <= n; i++){ cin >> l[i] >> a[i] >> b[i]; pom[i] = {a[i],i}; miniA = min(miniA,a[i]); miniA = min(miniB,b[i]); maxiA = max(maxiA,a[i]); maxiB = max(maxiB,b[i]); } if(miniB < miniA || maxiB > maxiA){ cout << "NIE" << '\n'; continue; } long long sumA = 0,sumB = 0; sort(pom + 1, pom + n + 1); bool nie = 0; int temp = pom[1].nd; if(a[temp] > b[temp]){ cout << "NIE" << '\n'; continue; } for(int i = 1; i <= n; i++){ int id = pom[i].nd; int tA = a[id]; int tB = b[id]; int litr = l[id]; sumA += litr * tA; sumB += litr * tB; if(sumA > sumB){ cout << "NIE" << '\n'; nie = 1; break; } } if(sumA != sumB) cout << "NIE" << '\n'; else if(!nie) cout << "TAK" << '\n'; } return 0; } |
English