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

////////////////////////////////////////////////////////////////////////////////

#define MEMORY_LIMIT 1000000 + 1

bool LOW_LEVEL(const std::vector<int32_t> &a, const std::vector<int32_t> &b) {
	return (a[1] + 1) - a[0] - a[2] < (b[1] + 1) - b[0] - b[2];
}

bool TOR_LEVEL(const std::vector<int32_t> &a, const std::vector<int32_t> &b) {
	return a[1] < b[1];
}

////////////////////////////////////////////////////////////////////////////////

int main(void) {
	int32_t n, m;

	scanf("%d %d", &n, &m);

	int32_t RR[MEMORY_LIMIT] = {0};

	std::vector<std::vector<int32_t>> DB;

	int32_t K = 0;

	for (size_t i = 0; i < n; i++) {
		int32_t p, k, c;
		scanf("%d %d %d", &p, &k, &c);

		if (k > K)
			K = k;

		DB.push_back({p, k, c});
	}

	std::sort(DB.begin(), DB.end(), LOW_LEVEL);

	for (size_t i = 0; i < n; i++) {
		int32_t p = DB[i][0], k = DB[i][1], c = DB[i][2];

		std::vector<std::vector<int>> A;

		for (size_t j = p; j < k; j++)
			if (RR[j] < m)
				A.push_back({static_cast<int>(j), RR[j]});

		if (A.size() < c) {
			printf("NIE");
			return 0;
		}

		std::sort(A.begin(), A.end(), TOR_LEVEL);

		for (size_t j = 0; j < A.size(); j++) {
			if (c == 0)
				break;
			RR[A[j][0]] += 1;
			c -= 1;
		}
	}

	printf("TAK");
	return 0;
}