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
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

const int SIZE = 100000;

typedef struct _info
{
	int id;
	int less;
	int diff;
} info;

int compare1 (const void * a, const void * b)
{
	return ( ((info*)a)->less - ((info*)b)->less );
}
int compare2 (const void * a, const void * b)
{
	return ( ((info*)b)->less - ((info*)a)->less );
}


int main()
{

	info in_plus[SIZE];
	info in_minus[SIZE];
	
	int n, z, d, a;

	scanf("%d %d\n", &n, &z);

	int p = 0, m = 0;

	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d\n", &d, &a);
	
		if (a >= d)
		{
			in_plus[p].id = i+1;
			in_plus[p].less = d;
			in_plus[p++].diff = a-d;
		}
		else
		{
			in_minus[m].id = i+1;
			in_minus[m].less = d;
			in_minus[m++].diff = a-d;
		}
	}

	qsort (in_plus, p, sizeof(info), compare1);
	qsort (in_minus, m, sizeof(info), compare2);

	bool err = false;
	for (int i = 0; i < p; ++i)
	{
		err = (z <= in_plus[i].less);
		if (err)
			break;
		z += in_plus[i].diff;
	}
	if (!err)
		for (int i = 0; i < m; ++i)
		{
			err = (z <= in_minus[i].less);
			if (err)
				break;
			z += in_minus[i].diff;
		}

	if (err)
		printf ("NIE\n");
	else
	{
		printf("TAK\n");
		for (int i = 0; i < p; ++i)
			printf("%d ", in_plus[i].id);
		for (int i = 0; i < m; ++i)
			printf("%d ", in_minus[i].id);
		printf("\n");
	}

	return 0;
}