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
#include <stdio.h>
#include <vector>
#include <algorithm>

bool check(const std::vector<std::pair<int, int>> vdata)
{
    int last_position   = vdata[0].first;
    long long collect   = 0LL;
    long long potential = 0LL;
    
    for (int i = 0; i < vdata.size(); i++)
    {
        potential += (vdata[i].first - last_position) * collect;
        
        if (potential < 0) return false;
        
        collect += vdata[i].second;
        last_position = vdata[i].first;
    }
    
    return (potential == 0);
}

int main()
{
    int T, n;
    std::vector<std::pair<int, int>> vdata;

    scanf("%d", &T);
    while (T--)
    {
        scanf("%d", &n);
        
        vdata.clear();
        
        for (int i = 0; i < n; i++)
        {
            int l, a, b;
            
            scanf("%d%d%d", &l, &a, &b);
            vdata.push_back(std::make_pair(a,  l));
            vdata.push_back(std::make_pair(b, -l));
        }
        
        std::sort(vdata.begin(), vdata.end());
        
        if (check(vdata))
            printf("TAK\n");
        else
            printf("NIE\n");
    }
    
    return 0;
}