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

typedef long long LL;

#define REP(i,n) for(int i=0;i<(n);++i)

const int MAX = 100000;

struct monster {
	int d, a, id;
	bool operator<(const monster &rhs) const {
		int g = a - d, rhsg = rhs.a - rhs.d;
		if(g <= 0 && rhsg <= 0) return a > rhs.a;
		if(g <= 0) return false;
		if(rhsg <= 0) return true;
		return d < rhs.d;
	}
};

monster arr[MAX];
int n;
LL k;

int main(int argc, char *argv[]) {
	scanf("%d %lld", &n, &k);
	REP(i,n)
	{
		scanf("%d %d", &arr[i].d, &arr[i].a);
		arr[i].id = i;
	}
	sort(arr, arr+n);
	REP(i,n)
		if(k <= arr[i].d) {
			printf("NIE\n");
			return 0;
		} else k = k - arr[i].d + arr[i].a;
	printf("TAK\n");
	REP(i,n) printf("%d ", arr[i].id+1); printf("\n");
	return 0;
}