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

using namespace std;

int main()
{
    int dataSets, bajtniatka,
        currentTemp, maxTemp, minTemp,
        currentRequiredTemp, maxRequiredTemp, minRequiredTemp,
        currentBitrs, bitrsOfMaxTemp, bitrsOfMinTemp;

    cin >> dataSets;

    for (int i = 0; i < dataSets; ++i)
    {
        cin >> bajtniatka;

        maxTemp = 0, minTemp = 0,
        maxRequiredTemp = 0, minRequiredTemp = 0,
        bitrsOfMaxTemp = 0, bitrsOfMinTemp = 0;

        for (int j = 0; j < bajtniatka; ++j)
        {
            cin >> currentBitrs >> currentTemp >> currentRequiredTemp;
            if (currentTemp != currentRequiredTemp)
            {
                if (maxTemp < currentTemp)
                {
                    maxTemp = currentTemp;
                    bitrsOfMaxTemp = currentBitrs;
                }
                if (minTemp > currentTemp)
                {
                    minTemp = currentTemp;
                    bitrsOfMinTemp = currentBitrs;
                }
                if (maxRequiredTemp < currentRequiredTemp)
                    maxRequiredTemp = currentRequiredTemp;
                if (minRequiredTemp > currentRequiredTemp)
                    minRequiredTemp = currentRequiredTemp;
            }
        }

        if ((maxTemp != 0 && minTemp >= maxTemp) || (maxRequiredTemp != 0 && minRequiredTemp >= maxRequiredTemp) ||
            minTemp > minRequiredTemp || maxTemp < maxRequiredTemp)
            cout << "NIE" << endl;
        else
            cout << "TAK" << endl;

        }

    return 0;
}