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

using namespace std;

typedef pair<int,int> para;
typedef pair<para,int> para2;

struct cmp
{
	bool operator() (const para2 a, const para2 b)
	{
		if (a.first.first > b.first.first) return false;
		if (a.first.first < b.first.first) return true;
		return a.first.second < b.first.second;
	}
};
const int ROZM = 100009;

bool odw[ROZM];
int n, poz, a, sum[ROZM], b, pom = 0, suma = 0;
vector<para2> wek, wek1, wek2;
vector<int> wynik;
int main()
{
	scanf("%d%d",&n,&poz);
	for (int i = 1; i <= n;i++)
	{
		scanf("%d%d",&a,&b);
		if (a <= b)
			wek.push_back(para2(para(a,b),i));
		else
		{
			wek1.push_back(para2(para(a,b),i));
			suma += (a-b);
			sum[i] = a - b;
		}
	}
	sort(wek.begin(),wek.end());
	for (int i = 0; i < wek.size(); i++)
	{
		int x = wek[i].first.first;
		int y = wek[i].first.second;
		int z = wek[i].second;
		if (poz <= x)
		{
			printf("NIE\n"); return 0;
		}
		else
		{
			poz += (y - x);
			wynik.push_back(z);
		}
	} // OKEJ
	
	for (int i = 0; i < wek1.size(); i++)
		wek2.push_back(para2(para(suma + wek1[i].first.second, wek1[i].first.first), wek1[i].second));
	sort(wek2.begin(),wek2.end(),cmp());
	for (int i = wek2.size() - 1; i >= 0; i--)
	{
		int x = wek2[i].first.first;
		int y = wek2[i].first.second;
		int z = wek2[i].second;
		//printf("%d %d %d\n",wek2[i].first.first,wek2[i].first.second, wek2[i].second);
		if (poz <= y)
		{
			printf("NIE\n"); return 0;
		}
		else
		{
			poz -= sum[wek2[i].second];
			wynik.push_back(z);
		}
	}
	printf("TAK\n");
	for (int i = 0; i < wynik.size(); i++)
		printf("%d ",wynik[i]);
	return 0;
}