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
#include<cstdio>
#include<algorithm>
using namespace std;

struct pot
{
int z,p,nr;
};

pot tp[100009];

bool comp(pot a, pot b)
{
int ra,rb;
ra=a.p-a.z;
rb=b.p-b.z;
if(ra>0 && rb<0) return true;
else if(ra<0 && rb>0) return false;
else if(ra>0 && a.z<b.z) return true;
else if(ra>0 && a.z>b.z) return false;
else if(a.p>b.p) return true;
else return false;
}

int main()
{
int n,z;
scanf("%d%d",&n,&z);
for (int i=0;i<n;i++)
{
	scanf("%d%d",&tp[i].z,&tp[i].p);
	tp[i].nr=i;
}
sort(tp,tp+n,comp);
			//for (int i=0;i<n;i++) printf("%d %d\n",tp[i].z,tp[i].p);
for (int i=0;i<n;i++)
{
		//printf("%d %d %d\n",tp[i].z,tp[i].p,z);
	if(z-tp[i].z>0) z+=tp[i].p-tp[i].z;
	else
	{
		printf("NIE");
		return 0;
	}
}
printf("TAK\n");
for (int i=0;i<n;i++) printf("%d ",tp[i].nr+1);
return 0;
}