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
84
85
86
87
88
89
90
91
#include <stdio.h>

int main(void) {
	unsigned int mCount, i, killed = 0;
    long long int health;
	
	scanf("%u", &mCount);
	scanf("%llu", &health);
	
    unsigned int monsters[mCount][3], kills[mCount];
	
	for (i=0; i<mCount;i++)
	{
		scanf("%u %u", &monsters[i][0], &monsters[i][1]);
		monsters[i][2] = 0;
	}
	
	int canContinue = 1, monster_pos = -1;
	
	while(canContinue) // kill the rest of mosters starting with most hardest
	{
		monster_pos = -1;
		
		for (i=0; i<mCount;i++) // kill all bots which will increase heroe's health (or 0 health increased);
		{
			int h = monsters[i][1] - monsters[i][0];
			
			if( monsters[i][2]==0 && h>=0 && (health - monsters[i][0]) > 0)
			{
				kills[killed] = i + 1;
				monsters[i][2] = 1;
				health += h;
				killed += 1;
				monster_pos = i;
			}
		}
		
		if(monster_pos == -1) //if not killable monsters found then stop loop
			canContinue = 0;
		
	}

	canContinue = 1;

	while(canContinue) // kill the rest of mosters starting with most hardest
	{
		monster_pos = -1;
		
		for (i=0; i<mCount;i++) // find hardest bot to kill
		{
			if(monsters[i][2]==0){ // if not killed yet	i then do more checks
			
				if(monster_pos == -1) //if first then assign in order to farther comparings
					monster_pos = i;
				else
					if(monsters[i][0]>monsters[monster_pos][0])
						monster_pos = i;
				
			}
		}
		
		if(monster_pos == -1) //if not killable monsters found then stop loop
			canContinue = 0;
		else
		{
			health -= monsters[monster_pos][0];
			
			if(health < 1) //if lower than 1 then heroe died{
				canContinue = 0;
			else
			{
				health += monsters[monster_pos][1];
				kills[killed] = monster_pos + 1;
				monsters[monster_pos][2] = 1; //mark as killed
				killed += 1; //advance to next position
			}
		}
	}
	
	if(killed == mCount)
	{
		printf("TAK\n");
		
		for (i=0; i<mCount;i++)
			printf("%d ", kills[i]);
	}
	else
		printf("NIE");

	return 0;
}