#define make_pair mp #define emplace_back pb #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, INF = 1e6 + 5; int n, t, a, b, l; map<int, long long> mapa, odl1, odl2; int main() { scanf("%d", &t); while(t--) { mapa.clear(); odl1.clear(); odl2.clear(); scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%d%d%d", &l, &a, &b); mapa[a] += l; mapa[b] -= l; } long long cnt = 0; long long res = 0; long long prev = 0; bool bad = 0; for(auto it : mapa) { res += (long long)(it.first - prev) * cnt; if(res < 0) bad = 1; cnt += it.second; odl1[it.first] = res; prev = it.first; } auto it = mapa.end(); it--; cnt = 0; res = 0; prev = 0; while(true) { res += (long long)(prev - it -> first) * cnt; if(res < 0) bad = 1; cnt += it -> second; prev = it -> first; odl2[it -> first] = res; if(it == mapa.begin()) break; it--; } if(odl1 == odl2 && !bad) printf("TAK\n"); else printf("NIE\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 | #define make_pair mp #define emplace_back pb #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, INF = 1e6 + 5; int n, t, a, b, l; map<int, long long> mapa, odl1, odl2; int main() { scanf("%d", &t); while(t--) { mapa.clear(); odl1.clear(); odl2.clear(); scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%d%d%d", &l, &a, &b); mapa[a] += l; mapa[b] -= l; } long long cnt = 0; long long res = 0; long long prev = 0; bool bad = 0; for(auto it : mapa) { res += (long long)(it.first - prev) * cnt; if(res < 0) bad = 1; cnt += it.second; odl1[it.first] = res; prev = it.first; } auto it = mapa.end(); it--; cnt = 0; res = 0; prev = 0; while(true) { res += (long long)(prev - it -> first) * cnt; if(res < 0) bad = 1; cnt += it -> second; prev = it -> first; odl2[it -> first] = res; if(it == mapa.begin()) break; it--; } if(odl1 == odl2 && !bad) printf("TAK\n"); else printf("NIE\n"); } return 0; } |