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

#define fru(j,n) for(int j=0;j<n;++j)
#define tr(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();++it)
#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;

const int MAXN= 100005;

typedef pair<pii,int> smok;
smok S[MAXN];

bool cmp(smok a, smok b) //czy a < b
{
	bool c1=a.x.x<=a.x.y,
		 c2=b.x.x<=b.x.y;
	if(c1!=c2) return c1>c2;
	if(c1==1) return a<b;
	return a.x.y!=b.x.y?a.x.y>b.x.y:a<b;
}

int main()
{
	int n;
	LL z;
	scanf("%d %lld",&n,&z);
	fru(i,n) scanf("%d%d",&S[i].x.x,&S[i].x.y);
	fru(i,n) S[i].y=i;
	sort(S,S+n,cmp);
	fru(i,n)
	{
		if(S[i].x.x>=z)
		{
			printf("NIE\n");
			return 0;
		}
		z+=S[i].x.y-S[i].x.x;
	}
	printf("TAK\n");
	fru(i,n) printf("%d ",S[i].y+1);printf("\n");
	return 0;
}