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
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

class Potwor {
  public:
    int attack;
    int bonus;
    int idx;

    bool isPositive() const {
      return attack <= bonus;
    }
};

ostream& operator<<(ostream& out, const Potwor& o)
{
  out << "Potwor(idx: " << o.idx << ", att: " << o.attack << ", bonus: " << o.bonus << ")";
  return out;
}

bool potwory_less(const Potwor& a, const Potwor& b) {
  switch (a.isPositive() - b.isPositive()) {
    case 1:
      return true;
    case -1:
      return false;
  }
  if (a.isPositive()) {
    return a.attack < b.attack;
  } else {
    return a.bonus > b.bonus
      || (a.bonus == b.bonus && a.attack > b.attack);
  }
}


int main() {
  int n, z;
  cin.sync_with_stdio(false);
  cin >> n >> z;
  vector<Potwor> potwory;

  for (int i = 0; i < n; i++) {
    Potwor p;
    p.idx = i + 1;
    cin >> p.attack >> p.bonus;
    potwory.push_back(p);
  }
  sort(potwory.begin(), potwory.end(), potwory_less);
  for (int i = 0; i < n; i++) {
    // cerr << potwory[i] << endl;
    z -= potwory[i].attack;
    // cerr << "Z after fight: " << z << endl;
    if (z <= 0) {
      cout << "NIE" << endl;
      return 0;
    }
    z += potwory[i].bonus;
    // cerr << "Z after bonus: " << z << endl;
  }
  cout << "TAK" << endl;
  for (int i = 0; i < n; i++) {
    cout << potwory[i].idx << " ";
  }
  cout << endl;

  return 0;
}