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
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define f first
#define s second

const int size = 100004;
pair<pair<long long, long long>, int> A[size], B[size];
int result[size];

bool cmp (pair<pair<long long, long long>, int> a, pair<pair<long long, long long>, int> b) {
	long long x = a.f.s;
	long long y = b.f.s;
	if(x < y) return false;
	if(x > y) return true;
	return a>b;
}

int main() {
	int n; long long temp;
	scanf("%d %lld", &n, &temp);
	int a = 0, b = 0, r = 0;
	for(int i = 0; i<n; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		if(x<=y) A[a++] = make_pair(make_pair(x, y), i);
		else B[b++] = make_pair(make_pair(x, y), i);
	}
	sort(A, A+a);
	sort(B, B+b, cmp);
	//for(int i = 0; i<b; i++) printf("%lld %lld\n", B[i].f.f, B[i].f.s);
	int success = true;
	for(int i = 0; i<a; i++) {
		//printf("%d\n", temp);
		if(temp<=A[i].f.f) {
			success = false;
			break;
		}
		temp += A[i].f.s - A[i].f.f;
		result[r++] = A[i].s;
	}
	//printf("XXXX\n");
	for(int i = 0; i<b; i++) {
		//printf("%lld %lld\n", temp, B[i].f.f);
		if(temp<=B[i].f.f) {
			success = false;
			break;
		}
		temp += B[i].f.s - B[i].f.f;
		result[r++] = B[i].s;
	}
	if(success) {
		printf("TAK\n");
		for(int i = 0; i<n; i++) printf("%d ", result[i]+1);
		printf("\n");
	} else	printf("NIE\n");
	return 0;
}