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
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdarg>
using namespace std;
#define PB push_back
#define IT iterator
#define MP make_pair
#define EB emplace_back
#define F first
#define S second
#define X first
#define Y second
#define NL printf("\n")
#define SZ(v) ((int)(v).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define FORC(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#ifdef DBG
#define W(x) do { printf("%s:%d %s = %d\n", __func__, __LINE__, #x, x); } while (0)
#define DBGprint(format, ...) do { fprintf(stderr, "[%s:%d] " format, __func__, __LINE__, __VA_ARGS__); } while (0)
#else
#define W(X) do { } while (0)
#define DBGprint(...) do { } while (0)
#endif

typedef long double LD;
typedef double DL;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LD,LD> PLD;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<PII> VPII;
void memcheck()
{
#ifdef DBG
    char c[100];
    FILE *p = fopen("/proc/self/status","r");
    while (fgets(c,100,p) )
        if (strncmp("VmPeak",c,6)==0)
            fputs(c, stderr);
    fclose(p);
#endif
}
//------ /headers --------


const int MAXN = 100010;
typedef tuple<int, int, int> Trinity;
vector<Trinity> gain, loss;
VI results;
int n;
LL health;

bool compute() {
    for (Trinity& t : gain) {
        DBGprint("health: %lld\n", health);
        // nie przezyjemy
        if (health <= get<0>(t)) {
            return false;
        }
        health += get<1>(t) - get<0>(t);
        results.PB(get<2>(t));
    }
    for (Trinity& t : loss) {
        DBGprint("health: %lld\n", health);
        if (health <= get<0>(t)) {
            return false;
        }
        health += get<1>(t) - get<0>(t);
        results.PB(get<2>(t));
    }
    DBGprint("health: %lld\n", health);
    return true;
}

bool comp(const Trinity& t1, const Trinity& t2) {
    if (get<1>(t1) == get<1>(t2)) {
        return get<0>(t1) > get<0>(t2);
    }
    return get<1>(t1) > get<1>(t2);
}

int main() {
    scanf("%d%lld", &n, &health);
    REP(i, n) {
        int d, a;
        scanf("%d%d", &d, &a);
        if (d < a) {
            gain.EB(d, a, i);
        } else {
            loss.EB(d, a, i);
        }
    }

    sort(ALL(gain));
    sort(ALL(loss), comp);
    
    for (Trinity& t : gain) {
        DBGprint("gain: %d %d %d\n", get<0>(t), get<1>(t), get<2>(t));
    }
    for (Trinity& t : loss) {
        DBGprint("loss: %d %d %d\n", get<0>(t), get<1>(t), get<2>(t));
    }
    
    if (compute()) {
        printf("TAK\n");
        for (int& i : results) {
            printf("%d ", i + 1);
        }
        printf("\n");
    } else {
        printf("NIE\n");
    }
}