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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Mateusz Kurek, PA 2014
// 2B BOH

#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<sstream>
#include<cstring>
#include <string>

//#include <iostream>

using namespace std;

#define REP(i,v)for(int i=0;i<(v);++i)
#define FOR(i,x,v)for(int i=x;i<=(v);++i)
#define FORD(i,x,v)for(int i=x;i>=(v);--i)
#define VAR(v,n) __typeof(n) v = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin()); i != (c).end(); ++i)
#define ALL(c) (c).begin(), c.end()
#define PB push_back
#define SZ size
#define MP make_pair
#define FI first
#define SE second
#define CL clear()
#define RS resize
#define INFTY 1000000001
#define EPS 10e-9
#define SIZE(x) ((int)(x).size())

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef long long LL;
typedef vector<string> VS;

void show(PII p)
{printf("(%d %d)\n",p.FI,p.SE);}

void show(VI e)
{REP(i,SIZE(e)) printf("%d ",e[i]); printf("\n");}

void show(vector<PII> e)
{REP(i,SIZE(e)) printf("(%d %d) ",e[i].FI,e[i].SE); printf("\n");}

void show(VS e)
{REP(i,SIZE(e)) printf("%s\n",e[i].c_str());}

void show(VVI e)
{REP(i,SIZE(e)) show(e[i]);}

#define MAXN 100002

int ds[MAXN], as[MAXN], positive[MAXN], negative[MAXN];

bool positive_sort(int i, int j){
    if(ds[i] == ds[j]){
        return as[i] > as[j];
    }
    return ds[i] < ds[j];
}

bool negative_sort(int i, int j){
    if(as[i] == as[j]){
        return ds[i] > ds[j];
    }
    return as[i] > as[j];
}

int main()
{
    int n, d, a, diff, positive_index = 0, negative_index = 0;
    long long sum = 0, z;
    scanf("%d %lld", &n, &z);
    FOR(i, 1, n){
        scanf("%d %d", &d, &a);
        diff = a - d;
        ds[i] = d;
        as[i] = a;
        sum += diff;
        if(diff >= 0){
            positive[positive_index++] = i;
        }
        else{
            negative[negative_index++] = i;
        }
    }
    // printf("sum: %d, positive_index: %d, negative_index: %d, z: %lld\n", sum, positive_index, negative_index, z);

    if(sum + z <= 0){
        printf("NIE\n");
        return 0;
    }
    sort(positive, positive+positive_index, positive_sort);
    sort(negative, negative+negative_index, negative_sort);

    // VI positivev(positive, positive+positive_index), negativev(negative, negative+negative_index);
    // printf("\npositive sorted: ");
    // show(positivev);
    // printf("negative sorted: ");
    // show(negativev);

    REP(i, positive_index){
        z -= ds[positive[i]];
        if(z <= 0){
            printf("NIE\n");
            // printf("NIE 2\n");
            return 0;
        }
        z += as[positive[i]];
    }
    REP(i, negative_index){
        z -= ds[negative[i]];
        if(z <= 0){
            printf("NIE\n");
            // printf("NIE 3, z = %lld, i = %i, ds[i] = %d\n", z, negative[i], ds[negative[i]]);
            return 0;
        }
        z += as[negative[i]];
    }
    printf("TAK\n");
    REP(i, positive_index){
        printf("%d ", positive[i]);
    }
    REP(i, negative_index){
        printf("%d ", negative[i]);
    }
    printf("\n");
}