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

using namespace std;

int n,m; 
int p[105];
int k[105];
int c[105];

int main()
{
	cin>>n>>m;
	for(int i=0; i<n; i++)
		cin>>p[i]>>k[i]>>c[i];
	int beg = 10000000;
	int end = 0;
	for(int i=0; i<n; i++)
	{
		beg = min(beg, p[i]);
		end = max(end, k[i]);
	}
	for(int tim=beg; tim<end; tim++)
	{
		vector<pair<int, int> >  v;
		for(int i =0; i<n; i++)
		{
			if(tim >= p[i] && tim <= k[i] && c[i] > 0)
				v.push_back({ k[i]-c[i] , i});
		}
		sort(v.begin(), v.end());
		int u = min (m, (int)v.size());
		for(int i=0; i<u; i++)
		{
			--c[v[i].second];
		}
	}

	bool ok = true;
	for(int i=0; i<n; i++)
		if(c[i] != 0)
			ok = false;
	if(ok)
		cout<<"TAK"<<endl;
	else
		cout<<"NIE"<<endl;
}