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

using namespace std;

int n, a, b;
long long z;

vector <int> result;

vector < pair <int, int> > gora[100005];
vector < pair <int, int> > dol[100005];
vector < pair <int, int> >::iterator it;

int main ()
{
	scanf("%d%lld",&n,&z);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d%d",&a,&b);
		if (a <= b) gora[a].push_back(make_pair(b, i));
		else dol[b].push_back(make_pair(a, i));
	}
	for (int i = 0; i <= 100000; ++i) for (it = gora[i].begin(); it != gora[i].end(); ++it)
	{
		if (z <= (long long)(i))
		{
	    	printf("NIE\n");
	    	return 0;
	    }
	    z += (long long)(it->first - i);
	    result.push_back(it->second);
	}
	for (int i = 100000; i >= 0; --i) for (it = dol[i].begin(); it!= dol[i].end(); ++it)
	{
		if (z <= (long long)(it->first))
		{
			printf("NIE\n");
			return 0;
		}
		z -= (long long)(it->first - i);
		result.push_back(it->second);
	}
	printf("TAK\n");
	for (int i = 0; i < n; ++i) printf("%d ",result[i]);
	return 0;
}