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 <bits/stdc++.h>

#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)

using namespace std;

typedef long long LL;

const int MAXN = 100010;
const int MAXD = 256 * 1024 + 3;
const int INF = 1000000010;

int n;
LL z;

struct monster{
	int dmg, pot, i;
} M[MAXN];

inline bool cmp(const monster &a, const monster &b){
	int sa = (a.dmg <= a.pot) ? 0 : 1;
	int sb = (b.dmg <= b.pot) ? 0 : 1;
	if(sa != sb) return sa < sb;
	if(sa == 0)
		return a.dmg < b.dmg;
	return a.pot > b.pot;
}

int main(){
	scanf("%d %lld", &n, &z);
	FWD(i,0,n){
		scanf("%d %d", &M[i].dmg, &M[i].pot);
		M[i].i = i;
	}
	sort(M, M+n, cmp);
	FWD(i,0,n){
		if(z <= M[i].dmg){
			printf("NIE\n");
			return 0;
		}
		z += M[i].pot - M[i].dmg;
	}
	printf("TAK\n");
	FWD(i,0,n) printf("%d ", M[i].i+1);
	printf("\n");
	return 0;
}