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
70
71
72
73
74
75
76
#include <iostream>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

struct obj {
	int first;
	int second;
	int id;
};

bool compare (obj T1, obj T2) {
	if(T1.second > T2.second)
		return 1;
	if(T1.second == T2.second && T1.first >= T2.first) {
		return 1;
	}	
	return 0;
}

int main(int argc, char** argv) {
	
	int n;
	int health;

	scanf("%d%d",&n, &health);
	
	vector< obj > T2;
	vector < obj >::iterator it;
	int T[100009];
	int counter = 0;
	obj  pomoc;
	int a,b;
	
	for(int i=1; i <= n; i++) {
		scanf("%d%d", &a, &b);
		if (b>a && health > a) {
			T[counter++] = i;
			health += (b-a);
		} else {
			pomoc.first = a;
			pomoc.second = b;
			pomoc.id = i;
			T2.push_back(pomoc);
		}
	}
	
	sort(T2.begin(),T2.end(),compare);
	for(it = T2.begin(); it != T2.end(); it++) {
		
		health -= (*it).first;
			if(health <= 0) {
				printf("NIE\n");
				return 0;
			} 
		health += (*it).second;	
		T[counter++] = (*it).id;
		
	}
	
	printf("TAK\n");
	for(int i=0; i<counter; i++) {
		printf("%d ",T[i]);
	}
	printf("\n");
	
	

	
	
	return 0;
}