Unfortunately we were unable to fully decode your file, as it is not encoded in UTF-8. You can try to decode it yourself by downloading it here.
 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
92
93
94
95
96
#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;

struct mob
{
	int nr;
	int hit;
	int pot;
};

bool profitOrder(const mob& m1, const mob& m2)
{
	return m1.hit < m2.hit;
}

bool riskOrder(const mob& m1, const mob& m2)
{
	if (m1.hit != m2.hit)
		return m1.hit > m2.hit;
	else
		return m1.pot > m2.pot;
}

//order:ilo�� �ycia, potem r�nica 

int main(int argc, char** argv)
{
	int monsters;
	int hp;

	scanf("%d %d", &monsters, &hp);

	vector<int> order;
	vector<mob> profit;
	vector<mob> risk;
	order.reserve(monsters);
	profit.reserve(monsters);
	risk.reserve(monsters);

	for (int i = 1; i <= monsters; i++)
	{
		int hit, pot;
		scanf("%d %d", &hit, &pot);

		if (hit <= pot && hit < hp)
		{
			order.push_back(i);
			hp += (pot - hit);
		}
		else if (hit <= pot)
		{
			profit.push_back({ i, hit, pot });
		}
		else
		{
			risk.push_back({ i, hit, pot });
		}
	}

	sort(begin(profit), end(profit), profitOrder);

	for (auto& x : profit)
	{
		if (x.hit >= hp)
		{
			printf("NIE");
			return 0;
		}

		hp += (x.pot - x.hit);
		order.push_back(x.nr);
	}

	sort(begin(risk), end(risk), riskOrder);

	for (auto& x : risk)
	{
		if (x.hit >= hp)
		{
			printf("NIE");
			return 0;
		}

		hp += (x.pot - x.hit);
		order.push_back(x.nr);
	}

	printf("TAK\n");

	for (auto x : order)
		printf("%d ", x);

}