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
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <tuple>
#include <queue>
using namespace std;
int main()
{
	long long int n, z, a, b, t=0, ii, mx;
	queue<int> kol;
	cin>>n>>z;
	tuple<int, int, int> tab[n];
	for(int i=0; i<n; i++)
	{
		//cin>>a>>b;
		scanf("%lli %lli", &a, &b);
		get<0>(tab[i])=a;
		get<1>(tab[i])=b-a;
		get<2>(tab[i])=i;
	}
	sort(tab, tab+n);
	for(int i=0; i<n; i++)
	{
		t=1;
		for(int i=n-1; i>=0; i--)
		{
			if(get<0>(tab[i])<z && get<2>(tab[i])!=-1)
			{
				t=0;
				ii=i;
				break;
			}
		}
		if(t!=0)
		{
			cout<<"NIE";
			break;
		}
		mx=INT_MIN;
		for(int i=ii; i<n; i++)
		{
			if(get<1>(tab[i])>mx && get<2>(tab[i])!=-1)
			{mx=get<1>(tab[i]);
			ii=i;
			}
		}
		z+=mx;
		kol.push(get<2>(tab[ii]));
		get<2>(tab[ii])=-1;
	}
	if(t==0)
	{
		cout<<"TAK"<<endl;
		while(kol.size()!=0)
	{
		cout<<kol.front()+1<<" ";
		kol.pop();
	}
	}
}