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
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstring>
#include <list>
#include <iostream>
using namespace std;
#define FOR(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i <= n; i++)
#define FORI(it,n)for(typeof(n.begin()) it = n.begin(); it != n.end(); it++)
#define frs first
#define sec second
#define psh push_back
#define mkp make_pair
typedef long long LL;
typedef long double LD;

const int INF = 2147483647;
const int MAX = 100100;

int n, z;
pair<int,int> A[MAX];
vector<int> V1, V2;

bool cmp(const int &a, const int &b) {
	return A[a].frs < A[b].frs;
}

bool solve(vector<int> &V, int s) {
	for(auto i: V) {
		if(s <= A[i].frs) return false;
		s -= A[i].frs;
		s += A[i].sec;
	}
	return true;
}

int main() {
	int s = 0;
	scanf("%d%d", &n, &z);
	s = z;
	FOR(i,n) {
		scanf("%d%d", &A[i].frs, &A[i].sec);
		s -= A[i].frs;
		s += A[i].sec;
		if(A[i].sec >= A[i].frs)
			V1.psh(i);
		else {
			V2.psh(i);
			swap(A[i].frs, A[i].sec);
		}
	}
	sort(V1.begin(), V1.end(), cmp);
	sort(V2.begin(), V2.end(), cmp);

	if(s <= 0) {
		printf("NIE\n");
		return 0;
	}

	if(!solve(V1, z)) {
		printf("NIE\n");
		return 0;
	}
	if(!solve(V2, s)) {
		printf("NIE\n");
		return 0;
	}

	printf("TAK\n");
	for(auto i: V1) printf("%d ", i+1);
	reverse(V2.begin(), V2.end());
	for(auto i: V2) printf("%d ", i+1);
	printf("\n");
}