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
69
70
71
72
73
74
75
76
77
#include <iostream>

using namespace std;

int main()
{
    cin.sync_with_stdio(false);
    int ile_t;
    cin >> ile_t;
    for(int i = 1; i <= ile_t; i++)
    {
        unsigned long int ile_zakladow;
        cin >> ile_zakladow;

        unsigned long int za, zb, zc, zd; // zbiorcze
        unsigned long int ca, cb, cc, cd; // champion
        unsigned long int ba, bb, bc, bd; // badane

        cin >> ba >> bb >> bc >> bd;
        bool champion = true; // czy jest champion
        za = ba;
        zb = bb;
        zc = bc;
        zd = bd;
        ca = ba;
        cb = bb;
        cc = bc;
        cd = bd;

        for(unsigned long int j = 2; j <= ile_zakladow; j++)
        {
            cin >> ba >> bb >> bc >> bd;
            if (ba < za) // powiekszanie zbiorczego zakresu
            {
                za = ba;
            }
            if (bb > zb)
            {
                zb = bb;
            }
            if (bc < zc)
            {
                zc = bc;
            }
            if (bd > zd)
            {
                zd = bd;
            }
            if((ba<=ca) && (bb>=cb) && (bc<=cc) && (bd>=cd))
            {
                ca = ba; //nowy champion
                cb = bb;
                cc = bc;
                cd = bd;
                champion = true;
            }
            if((ca<=za) && (cb>=zb) && (cc<=zc) && (cd>=zd))
            {
                champion = true;
            }
            else
            {
                champion = false;
            }
        }
        if (champion)
        {
            cout << "TAK" << endl;
        }
        else
        {
            cout << "NIE" << endl;
        }
    }

    return 0;
}