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

using namespace std;

struct monster{
	int no;
	int dmg;
	int hp;
	monster(int a, int b, int c): no(a), dmg(b), hp(c) {};
};

bool comp(monster m1, monster m2){
	if((m1.hp > 0 && m2.hp <= 0) || (m1.hp <= 0 && m2.hp > 0))
		return m1.hp > m2.hp;
	if(m1.hp > 0){
		if(m1.dmg == m2.dmg)
			return m1.hp > m2.hp;
		return m1.dmg <= m2.dmg;
	}
	if(m1.dmg == m2.dmg)
		return m1.hp > m2.hp;
	return m1.dmg > m2.dmg;
}

int main(){
	ios_base::sync_with_stdio(0);
	vector<monster> M;
	int n,hp,x,y;
	cin>>n>>hp;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		M.push_back(monster(i+1,x,y-x));
	}
	sort(M.begin(), M.end(), comp);
	int i;
	for(i=0 ; i<n; i++){
		if(hp - M[i].dmg > 0)
			hp += M[i].hp;
		else break;
	}
	if(i==n){
		cout<<"TAK"<<endl;
		for(i=0;i<n;i++) cout<<M[i].no<<" ";
	} else cout<<"NIE"<<endl;
	return 0;
}