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

#define ST first
#define ND second

using namespace std;

typedef long long int LL;

const int MX = 1e5+10;

int n;
LL d[MX], a[MX];
vector<int> g[3], out;
LL z;

bool cmp_ND(int A, int B) {
	return a[A] > a[B];
}

int main() {
	scanf("%d%lld", &n, &z);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%lld", &d[i], &a[i]);
		if (d[i] < a[i]) g[0].push_back(i);
		if (d[i] == a[i]) g[1].push_back(i);
		if (d[i] > a[i]) g[2].push_back(i);
	}
	sort(g[0].begin(), g[0].end());
	for (int i = 0; i < g[0].size(); i++) {
		int u = g[0][i];
		if (d[u] >= z) {
			printf("NIE\n");
			return 0;
		}
		z = z - d[u] + a[u];
		out.push_back(u);
	}
	for (int i = 0; i < g[1].size(); i++) {
		int u = g[1][i];
		if (d[u] >= z) {
			printf("NIE\n");
			return 0;
		}
		out.push_back(u);
	}
	sort(g[2].begin(), g[2].end(), cmp_ND);
	for (int i = 0; i < g[2].size(); i++) {
		int u = g[2][i];
		if (d[u] >= z) {
			printf("NIE\n");
			return 0;
		}
		out.push_back(u);
	}
	printf("TAK\n");
	for (int i = 0; i < out.size(); i++) printf("%d ", out[i]);
	printf("\n");
	return 0;
}