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
#include<bits/stdc++.h>
using namespace std;

long long temp[1000009];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++) {
        fill(temp, temp+1000006, 0);
        bool wrong = false;
        int n;
        cin >> n;
        for(int j = 0; j < n; j++) {
            long long v, t1, t2;
            cin >> v >> t1 >> t2;
            temp[t1] += v;
            temp[t2] -= v;
        }
        for(int j = 1; j <= 1000000; j++) {
            if(temp[j-1] < 0) {
                wrong = true;
                break;
            }
            temp[j] += 2*temp[j-1];
            temp[j+1] -= temp[j-1];
        }
        if(wrong)
            cout << "NIE\n";
        else
            cout << "TAK\n";
    }
}