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

using namespace std;
#define span_n(x, n) x, x+n

const int nmLim = 103;
const int inf = 10000003;
int n, m;
struct proc
{
	int p, k, kc;
	
	bool operator < (const proc &other) const
	{
		return kc < other.kc;
	}
} P[nmLim];

int main()
{
	scanf("%d%d", &n, &m);
	
	if(n <= m)
	{
		puts("TAK");
		return 0;
	}
	
	int p0 = inf, kn = 0;
	for(int i = 0; i < n; ++i)
	{
		int c;
		scanf("%d%d%d", &P[i].p, &P[i].k, &c);
		P[i].kc = P[i].k-c;
		p0 = min(p0, P[i].p);
		kn = max(kn, P[i].k);
	}
	
	int done = 0;
	for(int i = p0; i <= kn; ++i)
	{
		sort(span_n(P, n));
		for(int pI = 0, mI = 0; pI < n && mI < m; ++pI)
		{
			if(P[pI].p > i || P[pI].kc == P[pI].k)
				continue;
			if(P[pI].k <= i)
			{
				puts("NIE");
				return 0;
			}
			++mI;
			if(++P[pI].kc == P[pI].k)
				if(++done == n)
				{
					puts("TAK");
					return 0;
				}
		}
	}

	puts("NIE");
	
    return 0;
}