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

using namespace std;

typedef pair<size_t, size_t> Monster;
typedef vector<Monster> Monsters;

struct BySecond
{
  bool operator()(Monster const &l, Monster const &r) const
  {
    return l.second > r.second;
  }
};


int main()
{
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);

  size_t n, z;
  cin >> n >> z;

  Monsters m;
  m.reserve(n);

  size_t elixir(z);
  size_t hit(0);
  for(int i = 0; i < n; ++i)
  {
    Monster mh;
    cin >> mh.first >> mh.second;
    hit += mh.first;
    elixir += mh.second;
    m.push_back(std::make_pair(i + 1, mh.second));
  };

  if(hit >= elixir)
    cout << "NIE" << endl;
  else
  {
    cout << "TAK\n";
    std::sort(m.begin(), m.end(), BySecond());
    for(size_t i = 0; i < m.size(); ++i)
      cout << m[i].first << " ";
    cout << endl;
  }

  return 0;
}