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

using namespace std;

struct ele
{
	int a, b, c;
};

bool cmp1(ele l, ele r)
{
	return l.b < r.b;
}

bool cmp2(ele l, ele r)
{
	return l.c > r.c;
}

int main()
{
	ios_base::sync_with_stdio(false);
	
	int n, h;
	cin>>n>>h;
	
	vector< ele > plus, minus;
	bool ok = true;
	for(int i = 1; i <= n; i++)
	{
		int a, b;
		cin>>a>>b;
		if(b-a >= 0)
		{
			plus.push_back({i, a, b});
		} else
		{
			minus.push_back({i, a, b});
		}
		
	}
	
	sort(plus.begin(), plus.end(), cmp1);
	queue<int> wynik;
	for(int i = 0; i < plus.size(); i++)
	{
		wynik.push(plus[i].a);
		h += plus[i].c - plus[i].b;
	}
	
	sort(minus.begin(), minus.end(), cmp2);
	for(int i = 0; i < minus.size(); i++)
	{
		h += minus[i].c - minus[i].b;
		if(h > 0)
			wynik.push(minus[i].a);
		else
		{
			ok = false;
			break;
		}
	}
	
	if(ok)
	{
		cout<<"TAK"<<endl;
		while(!wynik.empty())
		{
			cout<<wynik.front()<<" ";
			wynik.pop();
		}
		cout<<endl;
	} else
		cout<<"NIE"<<endl;
	
	
}