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

using namespace std;

int main()
{
    uint64_t t,n, volume, currentTemp, wantedTemp, currentProduct=1, wantedProduct=1, currentMin=1000000, currentMax=1, wantedMin=1000000, wantedMax=1;
    cin>>t;
    for(int i=0; i<t; ++i)
    {
        cin>>n;

        currentMin=1000000;
        currentMax=1;
        wantedMin=1000000;
        wantedMax=1;
        currentProduct=1;
        wantedProduct=1;

        for(int j=0; j<n; ++j)
        {
            cin>>volume;
            cin>>currentTemp;
            cin>>wantedTemp;

            currentProduct += volume * currentTemp;
            wantedProduct += volume * wantedTemp;

            if(currentTemp > currentMax)
            {
                currentMax = currentTemp;
            }
            if(wantedTemp > wantedMax)
            {
                wantedMax = wantedTemp;
            }
            if(currentTemp < currentMin)
            {
                currentMin = currentTemp;
            }
            if(wantedTemp < wantedMin)
            {
                wantedMin = wantedTemp;
            }
        }

        if((currentProduct == wantedProduct) && (currentMax >= wantedMax) && (currentMin<=wantedMin))
        {
            cout<<"TAK"<<endl;
        }
        else
        {
            cout<<"NIE"<<endl;
        }
    }

}