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
77
78
79
80
81
82
83
#include <cstdio>
#include <vector>
#include <algorithm>

struct Enemy{
	unsigned int id;
	unsigned int strenght;
	unsigned int potion;

	bool operator()(const Enemy &e1, const Enemy &e2){

		if(e1.potion > e2.potion)return true;
		return false;
	}
};



using namespace std;

typedef vector<Enemy> evector;
typedef vector<Enemy>::iterator eiterator;


int main(){
	long long health; //Zycie bohatera
	unsigned int enemiesCount;

	vector<Enemy> enemies;
	vector<unsigned int> order;

	scanf("%u", &enemiesCount);
	scanf("%llu", &health);
	
	for(int i = 1; i <= enemiesCount; i++){
		Enemy enemy;
		enemy.id = i;
		scanf("%u", &enemy.strenght);
		scanf("%u", &enemy.potion);
		enemies.push_back(enemy);

	}

	std::sort(enemies.begin(), enemies.end(), Enemy());
	eiterator it = enemies.begin();
	eiterator end = enemies.end();

	while(enemies.size()){
		eiterator it = enemies.begin();
		eiterator end = enemies.end();

		for( ; it != end; it++){
			if((*it).strenght < health){
				health += ((*it).potion - (*it).strenght);
				order.push_back((*it).id);
				it = enemies.erase(it);
				break;
			}
		}

		if(it == end){
			break;
		}

	}

	if(enemies.size()){
		printf("NIE\n");
	}else{
		printf("TAK\n");

		vector<unsigned int>::iterator it = order.begin();
		vector<unsigned int>::iterator end = order.end();

		for(;it!=end; it++){
			printf("%u", *it);
			if((it+1)!= end) printf(" ");
			else printf("\n");
		}
	}

	return 0;
}