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
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
struct rek
{
    int b,a,nr;
    rek(int _a = 0, int _b = 0,int _nr=0) : a(_a), b(_b) , nr(_nr) {}
}t1[100000],t2[100000];
bool sortByA(const rek &x ,const rek & y)
{
    return x.a<y.a || (x.a==y.a && x.b>y.b);
}
bool sortByB(const rek &x ,const rek & y)
{
    return x.b>y.b || (x.b== y.b && x.a<y.a);
}

int main()
{
    int n;long long z;
    scanf("%d%lld",&n,&z);
    int ile1=0,ile2=0;
    for (int i=0;i<n;i++)
    {
	int a,b;scanf("%d%d",&a,&b);
	if(b>=a)
	{
	    t1[ile1++] = rek(a,b,i);
	}
	else
	    t2[ile2++] = rek(a,b,i);
    }
    sort(t1,t1+ile1,sortByA);
    sort(t2,t2+ile2,sortByB);
    vector<int> res; bool ok =true;
    for (int i=0;i<ile1;i++)
    {
	if(z-t1[i].a<=0)
	{
	    ok = false;break;
	}
	z+= t1[i].b-t1[i].a;
	res.push_back(t1[i].nr);
    }
    for (int i=0;i<ile2;i++)
    {
	if(z-t2[i].a<=0)
	{
	    ok = false;break;
	}
	z+= t2[i].b-t2[i].a;
	res.push_back(t2[i].nr);
    }
    if(!ok) printf("NIE\n"); else
    {
	printf("TAK\n");
	for (int i =0;i<res.size();i++)
	    printf("%d ",res[i]+1);
	printf("\n");
    }
}