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
#include <iostream>

using namespace std;

int main()
{
    int n; cin >> n;
    string ans[n];
    for(int p = 0;p < n;p++)
        ans[p] = "NIE";

    for(int p = 0;p < n;p++){
        int m; cin>>m;
        int tab[m][3];
        int MinTempWeHave=0,
            MaxTempWeHave=0,
            MaxTempWeWant=0,
            MinTempWeWant=0,
            SumaTempWeHave=0,
            SumaTempWeWant=0;

        for(int i = 0;i < m;i++){
            cin>>tab[i][0]>>tab[i][1]>>tab[i][2];
            if(MinTempWeHave > tab[i][1])       MinTempWeHave = tab[i][1];
            else if(MaxTempWeHave < tab[i][1])  MaxTempWeHave = tab[i][1];

            if(MinTempWeWant > tab[i][2])       MinTempWeWant = tab[i][2];
            else if(MaxTempWeWant < tab[i][2])  MaxTempWeWant = tab[i][2];

            SumaTempWeHave += tab[i][0] * tab[i][1];
            SumaTempWeWant += tab[i][0] * tab[i][2];

            if(SumaTempWeHave == SumaTempWeWant)
                ans[p] = "TAK";
            if(MinTempWeHave > MinTempWeWant || MaxTempWeHave < MaxTempWeWant)
                ans[p] = "NIE";

        }

    }
    for(int p = 0;p < n;p++)
        cout<<ans[p]<<endl;

    return 0;
}