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

typedef long long LL;

#define MAXN 100003

int n;
LL z;
LL d[MAXN],a[MAXN];
std::vector<int> P,N;

int main()
{
	scanf("%d%lld",&n,&z);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%lld%lld",d+i,a+i);
		if(d[i] - a[i] > 0)
			N.push_back(i);
		else
			P.push_back(i);
	}
	std::sort(P.begin(),P.end(),[&](int i,int j)->bool
	{
		return d[i] < d[j];
	});
	
	std::sort(N.begin(),N.end(),[&](int i,int j)->bool
	{
		return a[i] > a[j];
	});
	
	for(int i : P)
		if((z -= d[i]) <= 0) {puts("NIE");return 0;}
		else z += a[i];
	for(int i : N)
		if((z -= d[i]) <= 0) {puts("NIE");return 0;}
		else z += a[i];
	puts("TAK");
	for(int i : P) printf("%d ",i);
	for(int i : N) printf("%d ",i);
	return 0; 
}