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

struct Monster
{
  int damage, hpBonus, id;
};

struct Player
{
  unsigned long long hp;
  bool duel(const Monster& monster)
  {
    if((unsigned int)monster.damage >= this->hp)
      return false;
    this->hp += (monster.hpBonus - monster.damage);
    return true;
  }
};

int main(int argc, char** argv)
{
  std::ios_base::sync_with_stdio(false);
  Player player;
  int N;
  std::cin>>N>>player.hp;
  std::vector<Monster> monsters;
  monsters.reserve(N);
  for(int i = 0; i < N; ++i)
  {
    Monster m;
    std::cin>>m.damage>>m.hpBonus;
    m.id = i + 1;
    monsters.push_back(m);
  }
 
  std::sort(monsters.begin(), monsters.end(), 
    [](const Monster& lhs, const Monster& rhs)
      {
        int d1 = lhs.hpBonus - lhs.damage;
        int d2 = rhs.hpBonus - rhs.damage;
        if(d1 > 0 && d2 > 0)
          return lhs.damage < rhs.damage;
        if(d1 > 0)
          return true;
        if(d2 > 0)
          return false;
        if(lhs.damage == rhs.damage)
          return lhs.hpBonus > rhs.hpBonus;
        return lhs.damage > rhs.damage;
      });

  std::vector<int> result;
  result.reserve(N);
  for(auto it = monsters.begin(); it != monsters.end(); ++it)
  {
    if(!player.duel(*it))
    {
      std::cout<<"NIE"<<std::endl;
      return 0;
    }
    result.push_back(it->id);
  }
  
  std::cout<<"TAK"<<std::endl;
  for(auto it = result.begin(); it != result.end(); ++it)
  {
    std::cout<<(*it)<<" ";
  }
 
  return 0;
}