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
#include <cstdio>
#include <algorithm>
#define MP make_pair
#define ST first
#define ND second
using namespace std;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef long long LL;

const int N = 1e5;

int n, ix, iy;
PIII x[N], y[N];
LL zx, zy;

bool check(PIII t[], int n, LL z)
{
	sort(t, t+n);
	for (int i=0; i<n; ++i) {
		if (z <= t[i].ST.ST) return false;
		z += t[i].ST.ND;
	}
	return true;
}


int main()
{
	scanf("%d%lld", &n, &zx);
	zy = zx;
	
	for (int i=0, d, a; i<n; ++i) {
		scanf("%d%d", &d, &a);
		zy += a - d;
		
		PIII p = MP(MP(min(d, a), abs(d-a)), i);
		if (d <= a) x[ix++] = p;
		else y[iy++] = p;
	}
	
	if (check(x, ix, zx) && check(y, iy, zy)) {
		puts("TAK");
		for (int i=0; i<ix; ++i) printf("%d ", x[i].ND+1);
		for (int i=iy-1; i>=0; --i) printf("%d ", y[i].ND+1);
		putchar('\n');
	} else puts("NIE");
	
	return 0;
}