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 <vector>
#include <algorithm>

using namespace std;

struct monster
{
	int x;
	int d, a;
	bool operator<(const monster &m) const
	{
		// odwrotna kolejnosc sortowania
		if (a > m.a)
			return true;

		return false;
	}
};

int main(int argc, char ** argv)
{
	cin.sync_with_stdio(false);
	int n, z;
	cin >> n >> z;
	vector<monster> M(n);
	vector<int> Mq(n);
	int x = 1;
	for (vector<monster>::iterator it = M.begin(); it != M.end(); ++it, ++x)
	{
		(*it).x = x;
		cin >> (*it).d >> (*it).a;
	}
	sort(M.begin(), M.end());
	int i = 0;
	while (i < M.size())
	{
		if (z <= M[i].d)
		{
			cout << "NIE\n";
			return 0;
		}

		z -= M[i].d;
		z += M[i].a;
		Mq[i] = M[i].x;
		++i;
	}

	cout << "TAK\n";

	for (auto it = Mq.begin(); it != Mq.end(); ++it)
	{
		cout << (*it) << " ";
	}
	cout << "\n";
	return 0;
}