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
#include <stdio.h>

int main() {

	int number_of_tests;
	int number_of_manufacturers;
	bool tenderWinner;

	int w1, w2, h1, h2, wMin, wMax, hMin, hMax;

	scanf("%i", &number_of_tests);
	while (number_of_tests > 0) {
		scanf("%i", &number_of_manufacturers);
		scanf("%i %i %i %i", &wMin, &wMax, &hMin, &hMax);
		tenderWinner = true;
		while (number_of_manufacturers > 1) {

			scanf("%i %i %i %i", &w1, &w2, &h1, &h2);
			// nowy wynik jest lepszy lub taki sam, jak najlepszy dotychczas
			if(w1 <= wMin && w2 >= wMax && h1 <= hMin && h2 >= hMax) {
				tenderWinner = true;
				wMin = w1;
				wMax = w2;
				hMin = h1;
				hMax = h2;
			}
			// zmiana przedziałów - tymczasowy brak zwycięzcy
			else {
				if (w1 < wMin) {
					tenderWinner = false;
					wMin = w1;
				}
				if (w2 > wMax) {
					tenderWinner = false;
					wMax = w2;
				}
				if (h1 < hMin) {
					tenderWinner = false;
					hMin = h1;
				}
				if (h2 > hMax) {
					tenderWinner = false;
					hMax = h2;
				}
			}

			--number_of_manufacturers;
		}
		if (tenderWinner) {
			printf("TAK\n");
		}
		else {
			printf("NIE\n");
		}
		--number_of_tests;
	}

	return 0;
}