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
#include<cstdio>
#include<vector>
#include<algorithm>
#define LL long long
#define ST first
#define ND second
#define PB push_back
using namespace std;

struct node
{
	LL x, y, z;
	node(int x, int y, int z)
	{
		this->x = x;
		this->y = y;
		this->z = z;
	}
};

bool cmp(node x, node y)
{
	if(x.x == y.x)return x.y > y.y;
	return x.x < y.x;
}

vector<node> up, down;
vector<int> ans;

LL n, m, a, b;

int main()
{
	scanf("%lld%lld", &n, &m);
	for(int i = 0; i < n; i++)
	{
		scanf("%lld %lld", &a, &b);
		if(b >= a)up.PB(node(a, b, i+1));
		else
		{
			down.PB(node(-b, a, i+1));
		}
	}
	sort(up.begin(), up.end(), cmp);
	sort(down.begin(), down.end(), cmp);
	for(node &x : up)
	{
		if(x.x < m)m += x.y - x.x, ans.PB(x.z);
	}
	for(node &x : down)
	{
		if( x.y < m)m = m - x.y - x.x, ans.PB(x.z);
	}
	if((int)ans.size() == n)
	{
		printf("TAK\n");
		for(int i = 0; i < n; i++)
		{
			printf("%d ", ans[i]);
		}
		printf("\n");
	}
	else printf("NIE\n");
}