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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <cstdio>
#include <algorithm>

const int MAXN = 101010;

struct T {
	int dam, heal;
} a[MAXN];

int n;
int pos[MAXN];
int npos = 0;
int neg[MAXN];
int nneg = 0;
int ans[MAXN];
int nans = 0;

bool comp1(int i, int j) {
	return a[i].dam < a[j].dam;
}

bool comp2(int i, int j) {
	return a[i].heal > a[j].heal || a[i].heal == a[j].heal && a[i].dam < a[j].dam;
}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	long long x;
	scanf("%d%lld", &n, &x);
	for (int i = 0; i < n; i++)
		scanf("%d%d", &a[i].dam, &a[i].heal);
	for (int i = 0; i < n; i++)
		if (a[i].dam <= a[i].heal)
			pos[npos++] = i;
		else
			neg[nneg++] = i;
	std::sort(pos, pos + npos, comp1);
	for (int i = 0; i < npos; i++) {
		int k = pos[i];
		if (x <= a[k].dam) {
			printf("NIE\n");
			return 0;
		}
		else {
			x += a[k].heal - a[k].dam;
			ans[nans++] = pos[i];
		}
	}
	std::sort(neg, neg + nneg, comp2);
	for (int i = 0; i < nneg; i++) {
		int k = neg[i];
		if (x <= a[k].dam) {
			printf("NIE\n");
			return 0;
		}
		x += a[k].heal - a[k].dam;
		ans[nans++] = neg[i];
	}
	printf("TAK\n");
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i] + 1, i == n - 1 ? '\n' : ' ');
	return 0;
}