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 <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

typedef long long int ll;

using namespace std;

inline bool por(const pair<int, int> &a, const pair<int, int> &b)
{
	if(a.first <= a.second)
	{
		if(b.first <= b.second)
			return a.first < b.first;
		return true;
	}
	if(b.first <= b.second)
		return false;
	return a.second > b.second;
}

bool comp(const pair<int, pair<int, int> > &a, const pair<int, pair<int, int> > &b)
{
	return por(a.second, b.second);
}

int main()
{
	int n;
	ll z;
	vector<pair<int, pair<int, int> > > v;
	scanf("%d%lld", &n, &z);
	for(int i = 1; i <= n; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		v.push_back(make_pair(i, make_pair(a, b)));
	}
	sort(v.begin(), v.end(), comp);
	bool ok = true;
	for(int i = 0; i < v.size(); i++)
	{
		z -= v[i].second.first;
		if(z <= 0)
			ok = false;
		z += v[i].second.second;
	}
	if(ok)
	{
		printf("TAK\n");
		for(int i = 0; i < v.size(); i++)
			printf("%d ", v[i].first);
		printf("\n");
	}
	else
		printf("NIE\n");
	return 0;
}