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
#include <cstdio>
#include <algorithm>
#include <iterator>

    struct Car {
        int width;
        int initialPos;
        int finalPos;

        Car() { }

        Car(int width, int initialPos, int finalPos) {
            this->width = width;
            this->initialPos = initialPos;
            this->finalPos = finalPos;
        }

    };

    bool compare (const Car &o1, const Car &o2) {
                return o2.width < o1.width;
    }

    bool doJob(int maxWidth, std::vector<Car> cars) {
        std::sort (cars.begin(), cars.end(), compare);

        int middle = maxWidth/2;
        for (int i = 0; cars[i].width > middle; i++) {
            for (int j = i+1; cars[i].width + cars[j].width > maxWidth; j++) {
                if (cars[i].initialPos < cars[j].initialPos &&
                        cars[i].finalPos > cars[j].finalPos)
                    return false;
            }
        }
        return true;
    }

    int main() {
        int x1, y1, x2, y2;
        int numberOfTests;
        int numberOfCars, maxWidth;
        scanf( "%d", &numberOfTests );
        
        for (int i = 0; i < numberOfTests; i++) {
            scanf( "%d %d", &numberOfCars, &maxWidth );

            std::vector<Car> cars(numberOfCars+1);
            cars[numberOfCars].width = 0;

            for (int j = 0; j < numberOfCars; j++) {
                scanf( "%d %d %d %d", &x1, &y1, &x2, &y2 );

                cars[j].width = y2-y1;
                cars[j].initialPos = std::min(x1, x2);
            }
            for (int j = 0; j < numberOfCars; j++) {
                scanf( "%d %d %d %d", &x1, &y1, &x2, &y2 );

                cars[j].finalPos = std::min(x1, x2);
            }

            printf("%s\n", doJob(maxWidth, cars) ? "TAK" : "NIE" );
        }

        return 0; 
    }