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
#include<bits/stdc++.h>
using namespace std;
long long tests, a, b, poj, t1, t2, n, max1, min1, max2, min2;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> tests;
    for (int i = 0; i < tests; ++i)
    {
        cin >> n;
        a = 0, b = 0;
        max1 = 0, max2 = 0;
        min1 = INT_MAX, min2 = INT_MAX;
        for (int j = 0; j < n; ++j)
        {
            cin >> poj >> t1 >> t2;
            min1 = min(min1, t1);
            min2 = min(min2, t2);
            max1 = min(max1, t1);
            max2 = min(max2, t2);
            a += poj * t1;
            b += poj * t2;
        }
        if (a != b || max1 < max2 || min1 > min2) cout << "NIE\n";
        else cout << "TAK\n";
    }
    return 0;
}