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


const int MAX_N = 100000;
int n;
long long z;
int d[MAX_N], a[MAX_N];
vector<int> up, down;

bool sort_by_d(int lhs, int rhs) {
	return d[lhs] < d[rhs];
}

bool sort_by_a(int lhs, int rhs) {
	return a[lhs] > a[rhs];
}

int main()
{
	scanf("%d%ld", &n ,&z);
	for (int i=0; i<n; i++) {
		scanf("%d%d", d+i, a+i);
		if (d[i] <= a[i]) up.push_back(i);
		else down.push_back(i);
	}

	sort(up.begin(), up.end(), sort_by_d);
	sort(down.begin(), down.end(), sort_by_a);
	up.insert(up.end(), down.begin(), down.end());
	
	
	for (int i = 0; i < up.size(); i++) {
		if (z <= d[up[i]]) {
			printf("NIE\n");
			return 0;
		}

		z += a[up[i]] - d[up[i]];
	}
	
	printf("TAK\n");
	for (int i = 0; i < up.size(); i++)
		printf("%d ", up[i] + 1);
	printf("\n");

	
	return 0;
}