#include<cstdio>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
struct her{
ull l;
ull t;
bool operator<(her a) const{
return t < a.t;
}
};
static her tab[100000];
static her wym[100000];
int main(){
int t;
scanf("%i", &t);
while(t--){
int n;
scanf("%i", &n);
ull temp1 = 0, temp2 = 0;
for(int i = 0; i < n; ++i){
ull l, a, b;
scanf("%llu%llu%llu", &l, &a, &b);
tab[i].l = l;
tab[i].t = a;
temp1 += a * l;
wym[i].l = l;
wym[i].t = b;
temp2 += b * l;
}
if(temp1 != temp2){
puts("NIE");
continue;
}
sort(tab, tab + n);
sort(wym, wym + n);
int i1 = 0, i2 = 0;
ull mass1 = 0, mass2 = 0;
ull energy1 = 0, energy2 = 0;
bool flag = true;
while(i1 < n && i2 < n){
ull l1 = tab[i1].l;
ull t1 = tab[i1].t;
ull l2 = wym[i2].l;
ull t2 = wym[i2].t;
if(l1 + mass1 < l2 + mass2){
mass1 += l1;
energy1 += l1 * t1;
ull prop_en2 = energy2 + (mass1 - mass2) * t2;
++i1;
if(energy1 > prop_en2){
flag = false;
break;
}
}
else{
mass2 += l2;
ull prop_en1 = energy1 + (mass2 - mass1) * t1;
energy2 += l2 * t2;
++i2;
if(prop_en1 > energy2){
flag = false;
break;
}
}
}
if(flag){
puts("TAK");
}
else{
puts("NIE");
}
}
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include<cstdio> #include<algorithm> using namespace std; typedef unsigned long long ull; struct her{ ull l; ull t; bool operator<(her a) const{ return t < a.t; } }; static her tab[100000]; static her wym[100000]; int main(){ int t; scanf("%i", &t); while(t--){ int n; scanf("%i", &n); ull temp1 = 0, temp2 = 0; for(int i = 0; i < n; ++i){ ull l, a, b; scanf("%llu%llu%llu", &l, &a, &b); tab[i].l = l; tab[i].t = a; temp1 += a * l; wym[i].l = l; wym[i].t = b; temp2 += b * l; } if(temp1 != temp2){ puts("NIE"); continue; } sort(tab, tab + n); sort(wym, wym + n); int i1 = 0, i2 = 0; ull mass1 = 0, mass2 = 0; ull energy1 = 0, energy2 = 0; bool flag = true; while(i1 < n && i2 < n){ ull l1 = tab[i1].l; ull t1 = tab[i1].t; ull l2 = wym[i2].l; ull t2 = wym[i2].t; if(l1 + mass1 < l2 + mass2){ mass1 += l1; energy1 += l1 * t1; ull prop_en2 = energy2 + (mass1 - mass2) * t2; ++i1; if(energy1 > prop_en2){ flag = false; break; } } else{ mass2 += l2; ull prop_en1 = energy1 + (mass2 - mass1) * t1; energy2 += l2 * t2; ++i2; if(prop_en1 > energy2){ flag = false; break; } } } if(flag){ puts("TAK"); } else{ puts("NIE"); } } return 0; } |
English