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
// Konrad Szlesinski
#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
#include <limits>
using namespace std;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef long long LL;
typedef vector<LL> VLL;
typedef unsigned long long ULL;
typedef vector<ULL> VULL;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef set<int> SI;
typedef vector<SI> VSI;
typedef set<VI> SVI;
typedef multiset<int> mSI;
typedef map<int,int> MII;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REPD(i,n) FORD(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define FORED(it,c) for(VAR(it,(c).rbegin());it!=(c).rend();++it)
#define FORENA(it,c) for(VAR(it,(c).begin());it!=(c).end();)
#define ALL(c) (c).begin(),(c).end()
#define PF push_front
#define POF pop_front
#define PB push_back
#define POB pop_back
#define PH push_heap
#define POH pop_heap
#define INS insert
#define ER erase
#define MH make_heap
#define MP make_pair
#define FT first
#define SD second

VI L, W; // tabele strat i zyskow

bool hardest_first_cmp(int a, int b) {
    return L[a] >= L[b];
}

bool easiest_first_cmp(int a, int b) {
    return L[a] <= L[b];
}

int main() {

    ios_base::sync_with_stdio(false);

    int n;
    LL pts;
    cin >> n >> pts;

    VI plus, minus;
    int tmp1, tmp2;
    bool ans = true;

    REP(i, n)
    {
        cin >> tmp1 >> tmp2;
        L.push_back(tmp1);
        W.push_back(tmp2);
        if (tmp2 - tmp1 >= 0)
            plus.push_back(i);
        else
            minus.push_back(i);
    }

    sort(plus.begin(), plus.end(), easiest_first_cmp);
    sort(minus.begin(), minus.end(), hardest_first_cmp);

    FORE(it, plus)
    {
        pts -= (LL)L[*it];
        if(pts <= 0L)
        {
            ans = false;
            break;
        }
        pts += (LL)W[*it];
    }

    if(ans)
        FORE(it, minus)
        {
            pts -= (LL)L[*it];
            if(pts <= 0L)
            {
                ans = false;
                break;
            }
            pts += (LL)W[*it];
        }

    cout << (ans? "TAK" : "NIE") << endl;
    if(ans)
    {
        FORE(it, plus)
            cout << (*it) + 1 << " ";
        FORE(it, minus)
            cout << (*it) + 1 << " ";
        cout << endl;
    }

    return 0;
}