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
65
66
67
68
69
#include<cstdio>
#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>
using namespace std;


vector<pair<int, int>> input;


int sum(int index) {
	return -input[index].first + input[index].second;
}

bool sortFunc(int i, int j) {
	if (sum(i) > 0) {
		if (sum(j) > 0) {
			return input[i].first < input[j].first;
		}
		else
		{
			return true;
		}
	}
	else
	{
		if (sum(j) > 0) {
			return false;
		}
		else {
			return input[i].second > input[j].second;
		}
	}
}

int main() {

	int n, z;
	int loss, gain;

	vector<int> indices;

	scanf("%d %d", &n, &z);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &loss, &gain);
		input.push_back(make_pair(loss, gain));
		indices.push_back(i);
	}
	sort(indices.begin(), indices.end(), sortFunc);

	//simulation
	for (int i = 0; i < n; i++) {
		z -= input[indices[i]].first;
		if (z <= 0) break;
		z += input[indices[i]].second;
	}

	if (z <= 0) {
		printf("NIE\n");
	}
	else {
		printf("TAK\n");
		for (int i = 0; i < n; i++) {
			printf("%d ", indices[i] + 1);
		}
		printf("\n");
	}
}