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
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

struct Data {
    unsigned minW, maxW, minH, maxH;
};

int main(void) {
    cin.sync_with_stdio(false);

    unsigned numberOfTestSuites;
    cin >> numberOfTestSuites;

    for (unsigned i = 0; i < numberOfTestSuites; ++i) {
        unsigned numberOfSubconcractors;
        cin >> numberOfSubconcractors;

        vector<Data> offers;
        offers.reserve(numberOfSubconcractors);

        Data ref;
        ref.minW = numeric_limits<unsigned>::max();
        ref.maxW = 0;
        ref.minH = numeric_limits<unsigned>::max();
        ref.maxH = 0;

        for (unsigned j = 0; j < numberOfSubconcractors; ++j) {
            Data data;
            cin >> data.minW >> data.maxW >> data.minH >> data.maxH;

            ref.minW = min(data.minW, ref.minW);
            ref.maxW = max(data.maxW, ref.maxW);
            ref.minH = min(data.minH, ref.minH);
            ref.maxH = max(data.maxH, ref.maxH);

            offers.push_back(data);
        }

        vector<Data>::const_iterator it = offers.begin();
        for (; it != offers.end(); ++it) {
            if (it->minW > ref.minW) continue;
            if (it->maxW < ref.maxW) continue;
            if (it->minH > ref.minH) continue;
            if (it->maxH < ref.maxH) continue;
            break;
        }

        cout << ((offers.end() != it) ? "TAK" : "NIE") << endl;
    }
}