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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

typedef vector<int> VI;
typedef long long LL;
typedef pair<int, int> pii;

#define REP(x, n) for(int x = 0; x < (n); ++x)
#define MP(x,y) make_pair(x,y)
#define ALL(x) (x).begin(), (x).end()
#define FT first
#define ST second
#define FOREACH(i, c) for(typeof((c.begin())) i = (c).begin() ; i != (c).end(); ++i)
#define PB(x) push_back((x))
#define SZ(x) (int)x.size()
#define LN(x) (int)(x).length()

struct Pot {
    Pot(int d_, int a_, int i_) : d(d_), a(a_), i(i_) {}
    int d,a,i;
};

bool cmpPos(const Pot& p0, const Pot& p1) {
    return (p0.d == p1.d) ? (p0.a >= p1.a) : (p0.d < p1.d);
}

bool cmpNeg(const Pot& p0, const Pot& p1) {
    return (p0.a == p1.a) ? (p0.d >= p1.d) : (p0.a > p1.a);
}

void algo() {
    LL n,z; cin >> n >> z;
    vector<Pot> pos, neg;
    pos.reserve(n); neg.reserve(n);
    REP(i,n) {
	int d,a; cin >> d >> a;
	(a - d >= 0) ? pos.PB(Pot(d,a,i)) : neg.PB(Pot(d,a,i));
    }

    sort(ALL(pos), cmpPos);
    sort(ALL(neg), cmpNeg);

    REP(i, SZ(pos)) {
	if(z <= pos[i].d) { cout << "NIE\n"; return ;}
	z += pos[i].a - pos[i].d;
    }

    REP(i, SZ(neg)) {
	if(z <= neg[i].d) { cout << "NIE\n"; return ;}
	z += neg[i].a - neg[i].d;
    }

    cout << "TAK\n";
    REP(i, SZ(pos)) cout << pos[i].i + 1 << " ";
    REP(i, SZ(neg)) cout << neg[i].i + 1 << " ";
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    algo();

    return 0;
}