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

using namespace std;

struct Monster {
	int dmg;
	int heal;
	int index;
	
	bool operator<(const Monster& a) const
    {
		if(heal > dmg && a.heal > a.dmg){
			
			if(dmg==a.dmg){
				return heal > a.heal;
			} else {
				return dmg < a.dmg;
			}
		} else if(dmg > heal && a.dmg > a.heal){
			return heal > a.heal;
        }   else {
			
			return (heal-dmg) > (a.heal-a.dmg); 
		}
    }
};


main(){
	int i,n,hp,x,y;
	long long h;
	vector<Monster> monsters;
	scanf("%d %d", &n, &hp);
	h = hp;
	for(i=0;i<n;i++){
		Monster mon;
		scanf("%d %d", &x,&y);
		mon.dmg = x;
		mon.heal = y;
		mon.index = i;
		monsters.push_back(mon);
	}
	
	std::sort(monsters.begin(), monsters.end());
	
	for(vector<Monster>::iterator it = monsters.begin(); it != monsters.end(); ++it) {
		h -= it->dmg;
		if(h <= 0){
			printf("NIE\n");
			return 0;
		}
		h += it->heal;
	}
	printf("TAK\n");
	for(vector<Monster>::iterator it = monsters.begin(); it != monsters.end(); ++it) {
		printf("%d ", it->index+1);
	}
	printf("\n");
	return 0;
	
}