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

using namespace std;

typedef long long signed lls;

int n;
lls z;

int main()
{
	ios_base::sync_with_stdio(0);
	
	cin>>n>>z;
	vector<pair<int, pair<int, int> > > rosn;
	vector<pair<int, pair<int, int> > > malej;
	
	for(int i=0; i<n; i++)
	{
		int a, b;
		cin>>a>>b;
		if(a<=b)
			rosn.push_back(make_pair(a, make_pair(b, i+1)));
		else
			malej.push_back(make_pair(b, make_pair(a, i+1)));
	}
	
	lls curr = z;
	vector<int> wynik;
	
	sort(rosn.begin(), rosn.end());
	for(pair<int, pair<int, int> > p: rosn)
	{
		z -= p.first;
		if(z <= 0)
		{
			cout<<"NIE\n";
			return 0;
		}
		z += p.second.first;
		wynik.push_back(p.second.second);
	}
	
	sort(malej.rbegin(), malej.rend());
	for(pair<int, pair<int, int> > p: malej)
	{
		z -= p.second.first;
		if(z <= 0)
		{
			cout<<"NIE\n";
			return 0;
		}
		z += p.first;
		wynik.push_back(p.second.second);
	}
	
	cout<<"TAK\n";
	for(int w: wynik)
		cout<<w<<" ";
	cout<<"\n";
	
	return 0;
}