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 <bits/stdc++.h>

using namespace std;

struct Triple {
	int a, b, s, zw, index;
};

bool operator < (const Triple &a, const Triple &b) {
	if (a.zw != b.zw) return a.zw > b.zw;
	if (a.s != b.s) return a.s < b.s;
	if (a.b != b.b) return a.b > b.b;
	if (a.a != b.a) return a.a < b.a;
	return false;
}

int n, m, oks[105];
priority_queue<Triple> pq;
vector<Triple> vq;

int main () {
	scanf("%d%d", &n, &m);
	
	int mn = 1 << 30, mx = 0;

	vector<Triple> v(n, {0, 0, 0});
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d", &v[i].a, &v[i].b, &v[i].s);
		v[i].b--;
		v[i].zw = v[i].b - v[i].a - v[i].s + 1;
		v[i].index = i + 1;
		mx = max(mx, v[i].b);
		mn = min(mn, v[i].a);
		pq.push(v[i]);
	}

	for (int i = mn; i <= mx; i++) {
		int k = 0;
		while (!pq.empty()) {
			//printf("%d: {%d, %d, %d, %d}\n", pq.top().index, pq.top().a, pq.top().b, pq.top().s, pq.top().zw);
			if (k < m && pq.top().a <= i && pq.top().b >= i && pq.top().s > 0) {
				++k;
				oks[vq.size()] = 1;
			}
			if (pq.top().a > i || pq.top().b < i || pq.top().s == 0)
				oks[vq.size()] = 2;
			vq.push_back(pq.top()); pq.pop();
		}
		//printf("\n");
		for (int j = 0; j < vq.size(); j++) {
			if (oks[j] == 1){
				vq[j].s--;
			}
			else if(oks[j] == 0)
				vq[j].zw--;
			if (vq[j].zw < 0) {
				return printf("NIE\n"), 0;
			}
			oks[j] = 0;
			pq.push(vq[j]);
		}
		vq.clear();
	}
	while (!pq.empty()) {
		if (pq.top().s > 0)
			return printf("NIE\n"), 0;
		pq.pop();
	}
	return printf("TAK\n"), 0;
}

/*

1,1,2,2,2,2,6
3,3,3,4,3,5,7

*/