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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <iostream>
#include <list>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>
//#include "graph.h"
//#include "las.h"
//#include "lcs.h"
//include "textalg.h"


using namespace std;

int n, tmp2, tmp1;

long long z;

struct dg
{
    int in;
    int pot;
    int ID;
};

bool s1(dg a, dg b)
{
    if(a.in < b.in)
    {
        return true;
    }
    else
    {
        return false;
    }
}

dg in1[100001], in2[100001];

int main()
{
    cin>>n>>z;
    int i, in1it = -1, in2it = -1;
    for(i = 0; i < n; i++)
    {
        scanf("%d %d", &tmp1, &tmp2);
        if((tmp2 - tmp1)<0)
        {
            in1it++;
            in1[in1it].in = tmp1;
            in1[in1it].pot = tmp2;
            in1[in1it].ID = i + 1;
        }
        else
        {
            in2it++;
            in2[in2it].in = tmp1;
            in2[in2it].pot = tmp2;
            in2[in2it].ID = i + 1;
        }
    }
   // printf("P1\n");
    if(in1it > 0)
    {
        sort(in1, in1+in1it, s1);
    }
    if(in2it > 0)
    {
        sort(in2, in2+in2it, s1);
    }
   // printf("P2\n");

    //DBG
 //   for(i = 0; i <= in2it; i++)
   // {
     //   printf("nr: %d koszt: %d\n, zysk: %d\n", i, in2[i].in, in2[i].pot);
    //}
    //printf("\n");
   // for(i = 0; i <= in1it; i++)
    //{
    //    printf("nr: %d koszt: %d\n, zysk: %d\n", i, in1[i].in, in1[i].pot);
   // }
    //DGB

    for(i = 0; i <= in2it; i++)
    {
        z = z - (long long)in2[i].in;
        if(z <= 0)
        {
            printf("NIE");
            return 0;
        }
        z = z + (long long)in2[i].pot;
    }
    for(i = in1it; i >= 0; i--)
    {
        z = z - (long long)in1[i].in;
        if(z <= 0)
        {
            printf("NIE");
            return 0;
        }
        z = z + (long long)in1[i].pot;
    }
    printf("TAK\n");
    for(i = 0; i <= in2it; i++)
    {
        printf("%d ", in2[i].ID);
    }
    for(i = in1it; i >= 0; i--)
    {
        printf("%d ", in1[i].ID);
    }
    return 0;
}