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
#include <cstdio>
#include <list>

struct challenge{
	int index;
	int damage;
	int lifePoints;
	int diff;
};

bool compare_challenge(const challenge& a, const challenge& b) {
	if (a.diff >= 0 && b.diff >= 0) return (a.damage < b.damage);
	else if (a.diff >= 0 && b.diff < 0) return true;
	else if (a.diff < 0 && b.diff >= 0) return false;
	else return (a.lifePoints > b.lifePoints);
}

int main(int argc, char* argv[]) {
	// read first line
	int numberOfMonsters = 0;
	int hitPoints = 0;
	int initHitPoints = 0;
	scanf("%d %d", &numberOfMonsters, &initHitPoints);
	hitPoints = initHitPoints;
	// read input values and calculate
	// if hero can beat all monsters
	int damage = 0;
	int lifePoints = 0;
	int diff = 0;
	std::list<challenge> challenges;
	numberOfMonsters++;
	for (int i = 1; i < numberOfMonsters; ++i) {
		scanf("%d %d", &damage, &lifePoints);
		diff = lifePoints - damage;
		challenges.push_back({i, damage, lifePoints, diff});
		hitPoints += diff;
	}
	if (hitPoints > 0) {
		challenges.sort(compare_challenge);
		// check if hero can kill first monster
		if (initHitPoints > challenges.begin()->damage) {
			printf("TAK\n");
			for (std::list<challenge>::iterator it = challenges.begin(); it != challenges.end(); ++it) {
				printf("%d ", *it);
			}
		} else {
			printf("NIE");
		}
		printf("\n");
	} else {
		printf("NIE\n");
	}
	return 0;
}