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

using namespace std;

class boh
{
	public:
		
	int str;
	int hp;
	int idx;	
		
};

int sth(boh a, boh b)
{
	return(a.str < b.str);
}
int ssth(boh a, boh b)
{
	return(a.str > b.str);
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n, m;
	vector <boh> tabd;
	vector <boh> tabu;
	boh pom;
	long long walka;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
	{
		pom.idx = i + 1;
		cin >> pom.str >> pom.hp;
		if(pom.hp - pom.str >= 0)
		{
			tabd.push_back(pom);
		}
		else
		{
			tabu.push_back(pom);
		}
	}
	sort(tabd.begin(), tabd.end(), sth);
	sort(tabu.begin(), tabu.end(), ssth);
	walka = m;
	for(unsigned int i = 0; i < tabd.size(); i++)
	{
		walka -= tabd[i].str;
		if(walka <= 0)
		{
			cout << "NIE";
			return 0;
		}
		else
		{
			walka+= tabd[i].hp;
		}
	}
	for(unsigned int i = 0; i < tabu.size(); i++)
	{
		walka -= tabu[i].str;
		if(walka <= 0)
		{
			cout << "NIE";
			return 0;
		}
		else
		{
			walka+= tabu[i].hp;
		}
	}
	cout << "TAK" << "\n";
	for(unsigned int i = 0; i < tabd.size(); i++)
	{
		cout << tabd[i].idx << " ";
	}
	for(unsigned int i = 0; i < tabu.size(); i++)
	{
		cout << tabu[i].idx << " ";
	}
	return 0;
}