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 <cstdio>
#include <algorithm>
using namespace std;
int n, d [1000000], a [1000000], o [1000000];
long long z;
bool cmp (int x, int y) {
	if (a [x] > 0) {
		if (a [y] <= 0) return true;
		if (d [x] < d [y]) return true;
	}
	if (a [x] == 0) {
		if (a [y] <= 0) return true;
	}
	if (a [x] < 0 && a [y] < 0) {
		if (d [x] + a[x] > d[y] + a[y]) return true;
		if (d [x] + a[x] == d[y] + a[y] && d[x] > d[y]) return true;
	}


	return false;
}

int main () {
	scanf ("%d %lld", &n, &z);
	for (int i = 0; i < n; i ++) {
		scanf ("%d %d", &d [i], &a [i]);
		a [i] -= d [i];
		o [i] = i;
	}
	sort (o, o + n, cmp);

	for (int i = 0; i < n; i ++) {
		if (z - d[o[i]] <= 0) {
			printf ("NIE\n");
			return 0;
		}
		z += (long long int) a [o[i]];
	}
	printf ("TAK\n");
	for (int i = 0; i < n; i ++) printf ("%d ", o [i] + 1);
	printf ("\n");
}