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

struct monster{
	float damage;
	float HealthPoition;
	int number;
};

bool byDevice(monster const &a, monster const &b){
	if(a.damage == 0 && b.damage == 0){
		return (a.HealthPoition/0.001) > (b.HealthPoition/0.001);
	}else if(a.damage == 0){
		return (a.HealthPoition/0.001) > (b.HealthPoition/b.damage);
	}else if(b.damage == 0){
		return (a.HealthPoition/a.damage) > (b.HealthPoition/0.001);
	}else{
		return (a.HealthPoition/a.damage) > (b.HealthPoition/b.damage);
	}
}

int main(){
	int n = 0, hp = 0;
	bool result = true;
	
	cin >> n >> hp;
	monster tab[n];
	
	for(int i = 0 ; i < n ; i ++){
		cin >> tab[i].damage >> tab[i].HealthPoition;
		tab[i].number = i+1;
		
	}
	
	sort(tab, tab+n, &byDevice);
	
	for(int i = 0 ; i < n ; i ++){
		//cout << tab[i].damage << " " << tab[i].HealthPoition << " " << tab[i].number << endl; 
		hp -= tab[i].damage;
		if(hp <= 0){
			result = false;
			break;
		}
		hp += tab[i].HealthPoition;
	}
	
	if(!result){
		cout << "NIE" << endl;
	}else{
		cout << "TAK" << endl;
		for(int i = 0 ; i < n ; i ++){
			cout << tab[i].number << " "; 
		}
	}
	
	return 0;
}