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

using namespace std;

class Monster{
    public:
        int id;
        int damage;
        int potion;
        int compareValue;
        
        Monster(){
        }
        
        Monster(int _id, int _damage, int _potion){
            this->id = _id;
            this->damage = _damage;
            this->potion = _potion;
            if (_potion - _damage >= 0){
                this->compareValue = -100001 + _damage;
            }
            else{
                this->compareValue = 100000 - _potion;
            }
        };

        inline bool operator< (const Monster& right){
            return this->compareValue < right.compareValue;
        };
};


int main () {
    
    int amountOfMonstres;
    long long currentHP;
    cin >> amountOfMonstres >> currentHP;
    vector<Monster> monsters;
    int damage, potion;
    
    for(int id = 1; id<=amountOfMonstres; id++){
        cin >> damage >> potion;
        monsters.push_back(Monster(id,damage,potion));
    }
    make_heap (monsters.begin(), monsters.end());
    sort_heap (monsters.begin(),monsters.end());
    
    int iterator = 0;
    bool died = false;
    while((iterator<amountOfMonstres) && (!died)){
        if(currentHP - monsters[iterator].damage > 0){
            currentHP = currentHP - monsters[iterator].damage + monsters[iterator].potion;
        }
        else{
            died = true;
        }
        iterator++;
    }
    
    if(died){
        cout << "NIE\n";
    }
    else{
        cout << "TAK\n" << monsters[0].id;
        for (int i=1; i<amountOfMonstres; i++){
            cout << ' ' << monsters[i].id;
        }
        cout << '\n';
    }
    return 0;
};