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<algorithm>


using namespace std;


struct TYP
{
    int d;
    int a;
    int diff;
    int ix;
};

bool sortFunc(TYP x, TYP y)
{
    if( x.diff >= 0 && y.diff < 0)
        return true;
    if( x.diff < 0 && y.diff >= 0)
        return false;
    if( x.diff >= 0 && y.diff >= 0)
        return x.d < y.d;

    return x.a> y.a;
}


int main()
{
    int n, z;
    TYP dane[100000];
    scanf("%i %i", &n, &z);
    for(int i = 0; i < n; ++i)
    {
        scanf("%i %i", &(dane[i].d), &(dane[i].a));
        dane[i].ix = i+1;
        dane[i].diff = dane[i].a - dane[i].d;
    }

    sort(dane, dane+n, sortFunc);

    for(int i = 0; i < n; ++i)
    {
        //printf("z=%i ix=%i d=%i a=%i\n",z, dane[i].ix, dane[i].d, dane[i].a);
        z-= dane[i].d;
        if( z <= 0)
        {
            printf("NIE");
            return 0;
        }
        z+= dane[i].a;
    }


    printf("TAK\n");

    for(int i = 0; i < n; ++i)
    {
        printf("%i ", dane[i].ix);
    }

    return 0;
}