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
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>

#define FOR(i,a,b)  for(int i=(a);i<(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,a)    FOR(i,0,a)
#define MP          make_pair
#define PB          push_back
#define ST          first
#define ND          second

using namespace std;

typedef vector<int>             VI;
typedef vector<VI>              VVI;
typedef pair<int, int>          PII;
typedef vector<PII>             VII;
typedef long long int           LL;
typedef unsigned long long int  ULL;

const int MAXN = 100000+5;

int n;

LL z;
LL sum_neg = 0;
int pos = 0, neg = 0;
pair<PII, int> positive[MAXN];
pair<PII, int> negative[MAXN];
int result[MAXN];

int main() {
    scanf("%d %lld", &n, &z);
    int din, ain;
    REP (i, n) {
        scanf("%d %d", &din, &ain);
        if (ain >= din) {
            positive[pos] = {{din, ain-din}, i+1};
            ++pos;
        }
        else {
            sum_neg += ain-din;
            negative[neg] = {{ain, din-ain}, i+1};
            ++neg;
        }
    }

    sort(positive, positive + pos);
    sort(negative, negative + neg);

    REP (i, pos) {
        if (LL(positive[i].ST.ST) >= z) {
            printf("NIE\n");
            return 0;
        }
        z += positive[i].ST.ND;
        result[i] = positive[i].ND;
    }

    if (z + sum_neg <= 0) {
        printf("NIE\n");
        return 0;
    }
    z = z + sum_neg;

    REP (i, neg) {
        if (LL(negative[i].ST.ST) >= z) {
            printf("NIE\n");
            return 0;
        }
        z += negative[i].ST.ND;
        result[neg-i-1+pos] = negative[i].ND;
    }

    printf("TAK\n");
    REP (i, n) {
        printf("%d ", result[i]);
    }

    return 0;
}