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
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <algorithm>
#include <list>

using namespace std;
typedef long long int LL;

struct potwor
{
	LL d, a, nr;	
};

bool operator < (potwor A, potwor B)
{
	if(A.a < B.a)
		return true;
	if(A.a > B.a)
		return false;
	if(A.a == B.a)
	{
		if(A.d < B.d)
			return false;
		else
			return true;
	}
}

list <potwor> SPIS;
list <int> RESULT;

int main()
{
	LL n, z;
	cin >> n >> z;
	
	LL K = z;
	
	for(int i = 1; i <= n; i++)
	{
		potwor HASH; HASH.nr = i; 
		
		cin >> HASH.d >> HASH.a;
		K = K - HASH.d + HASH.a;
		
		SPIS.push_back(HASH);
	}
	
	SPIS.sort();
	
	int numer_rundy = n;
	
	while(numer_rundy != 0)
	{
		list <potwor> :: iterator X = SPIS.begin();
		
		while(K - X->a <= 0 && X != SPIS.end())
		{
			X++;
		}
		
		if(X == SPIS.end())
		{
			goto A;
		}
		else
		{
			RESULT.push_back(X->nr);
			
			K = K - X->a + X->d;
			
			X = SPIS.erase(X);
			
			numer_rundy--;
		}
	}
	
	RESULT.reverse();
	
	A:
	
	if(numer_rundy == 0)
	{
		cout << "TAK" << endl;
		
		for(list <int> :: iterator X = RESULT.begin(); X != RESULT.end(); X++)
		{
			int M = *X;
			
			cout << M << " ";
		}
	}
	else
	{
		cout << "NIE" << endl;
	}
	
	return 0;
}