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
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>

using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    for(int u=0;u^t;++u){
        int n;
        scanf("%d",&n);
        int*l=new int[n];
        int*a=new int[n];
        int*b=new int[n];

        int vala=0,mina=2000000000,maxa=0,ilemina=0,ilemaxa=0;
        int valb=0,minb=2000000000,maxb=0,ileminb=0,ilemaxb=0;
        for(int i=0;i^n;++i){
            scanf("%d%d%d",&l[i],&a[i],&b[i]);
            vala+=l[i]*a[i];
            valb+=l[i]*b[i];
            if(a[i]<mina){
                mina=a[i];
                ilemina=l[i];
            }
            if(a[i]>maxa){
                maxa=a[i];
                ilemaxa=l[i];
            }
            if(b[i]<minb){
                minb=b[i];
                ileminb=l[i];
            }
            if(b[i]>maxb){
                maxb=b[i];
                ilemaxb=l[i];
            }
        }
        //cout<<"maxb: "<<maxb<<", minb: "<<minb<<endl<<"maxa: "<<maxa<<", mina: "<<mina<<endl;
        if((vala==valb)&&(maxb<maxa)&&(minb>mina))
            printf("TAK\n");
        else if((vala==valb)&&(maxb==maxa)&&(minb>mina)){
            if(ilemaxa>=ilemaxb)
                printf("TAK\n");
            else
                printf("NIE\n");
        }
        else if((vala==valb)&&(maxb<maxa)&&(minb==mina)){
            if(ilemina>=ileminb)
                printf("TAK\n");
            else
                printf("NIE\n");
        }
        else if((vala==valb)&&(maxb==maxa)&&(minb==mina)){
            if(ilemaxa>=ilemaxb&&ilemina>=ileminb)
                printf("TAK\n");
            else
                printf("NIE\n");
        }
        else
            printf("NIE\n");

        delete[]l;
        delete[]a;
        delete[]b;
    }
    return 0;
}