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
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int min_year = 2020;
    int t,n;
    unsigned long long sumIn, sumOut;
    int minIn, maxIn, minOut, maxOut;
    int l, a, b;
    cin >> t;;
    while(t-->0){
        minIn = minOut = 1000001;
        maxIn = maxOut = -1;
        sumIn= sumOut = 0;
        cin >> n;
        for(int i=0; i < n; i++){
            cin >> l >> a >> b;
            sumIn += l*a;
            sumOut += l*b;
            minIn = minIn > a ? a : minIn;
            minOut = minOut > b ? b : minOut;
            maxIn = maxIn < a ? a : maxIn;
            maxOut = maxOut < b ? b : maxOut;
        }
        if( sumIn == sumOut && minIn <=minOut && maxIn >= maxOut)
        {
            cout << "TAK\n";
        }
        else 
        {
            cout << "NIE\n";
        }
    }
    return 0;
}