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

struct monster {
	int from, pts;
	int i;
};
vector <monster> positive;
vector <monster> negative;
int n, d0;

bool up() {
	sort(positive.begin(), positive.end(), [](monster a, monster b)->bool {
							return a.from < b.from; } );
	for(int i = 0; i < positive.size(); ++i) {
		if(positive[i].from >= d0)
			return false;
		d0 += positive[i].pts - positive[i].from;
	}
	return true;
}

bool down() {
	sort(negative.begin(), negative.end(), [](monster a, monster b)->bool {
							return a.pts > b.pts; } );
	for(int i = 0; i < negative.size(); ++i) {
		if(negative[i].from >= d0)
			return false;
		d0 += negative[i].pts - negative[i].from;
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &d0);
	for(int i = 0; i < n; ++i) {
		monster x;
		scanf("%d%d", &x.from, &x.pts);
		x.i = i + 1;
		if(x.pts < x.from)
			negative.push_back(x);
		else
			positive.push_back(x);
	}
	if(!up() || !down()) {
		printf("NIE\n");
		return 0;
	}
	printf("TAK\n");
	for(int i = 0; i < positive.size(); ++i)
		printf("%d ", positive[i].i);
	for(int i = 0; i < negative.size(); ++i)
		printf("%d ", negative[i].i);
	return 0;
}