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

#define FOR(i, n) for(__typeof(n) i = 0; i < (n); i++)
#define FORI(k, a, b) for (int k = (a); k < (b); k++)
#define FOREACH(i, c) for(__typeof((c.begin())) i=(c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back
#define len(a) (a).size()
#define st first
#define nd second

using namespace std;

int main() {
  // first do all the positive or neutral ones sorted by d in increasing order
  // then do all the negative - sorted by d in decreasing order
	ios_base::sync_with_stdio(0);
	int n, life;
  cin >> n >> life;
  int d[n], a[n];
  vector<pair<pair<int, int>, int> > pos, neg;
  vector<int> ans;
  FOR(i, n) {
    cin >> d[i] >> a[i];
    int diff = a[i] - d[i];
    if (diff < 0) {
      neg.PB(MP(MP(d[i], diff), i));
    } else {
      pos.PB(MP(MP(d[i], diff), i));
    }
  }
  sort(ALL(pos));
  sort(ALL(neg), std::greater<pair<pair<int, int>, int> >());
  FOREACH(i, pos) {
    int needed = i->st.st, diff = i->st.nd, index = i->nd;
    if (needed > life) {
      break;
    }
    life += diff;
    ans.PB(index);
  }
  FOREACH(i, neg) {
    int needed = i->st.st, diff = i->st.nd, index = i->nd;
    if (needed > life) {
      break;
    }
    life += diff;
    ans.PB(index);
  }
  if (len(ans) == n) {
    cout << "TAK" << endl;
    FOR(i, n) {
      cout << ans[i] + 1 << " ";
    }
  } else {
    cout << "NIE" << endl;
  }
}