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
/* 
 * File:   lustra.cpp
 * Author: Kamila
 *
 * Created on 14 maj 2014, 21:05
 */

#include <iostream>
#include <algorithm>

using namespace std;

/*
 * 
 */
 	int tablica[100000+2][2];
 	int strategia[100000+2];
 	struct cmp{
 		bool operator()(int i, int j){
 			if(tablica[i][1]-tablica[i][0]>=0){
 				if(tablica[j][1]-tablica[j][0]<0)
 				return true;
 				else {
 					if (tablica[i][0]<tablica[j][0])
 					return true;
 					else return false;
 				}
 			} else {
 				if(tablica[j][1]-tablica[j][0]>=0)
				 return false;
				 else {
				 	if(tablica[i][1]>tablica[j][1])
				 	return true;
				 	else return false;
				 } 				
 			}
 		}
 	};
int main() {
	ios_base::sync_with_stdio(0);
	long long z;
	int n;
	cin >> n >> z;
	for (int i = 1; i<n+1; i++){
		cin >> tablica[i][0] >> tablica[i][1];
		strategia[i]=i;
	}
	sort(strategia + 1,strategia + n+1, cmp());
	
	for (int i = 1; i<n+1; i++){
		z= z - tablica[strategia[i]][0];
		if(z<=0) {
			cout << "NIE\n";
			return 0;
		} else {
			z = z + tablica[strategia[i]][1];
		}
	}
	
	cout << "TAK\n";
	for (int i=1; i< n+1; i++){
		cout << strategia[i] << " ";
	}

}