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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct Monster{
    long long damage;
    long long bonusHp;
    long long number;
}monster;

vector<Monster> monsterBoss;
vector<Monster> monsterLittle;
vector<int> tab;

bool comp(Monster a, Monster b){
    return a.damage < b.damage;
}
bool comp2(Monster a, Monster b){
    return a.bonusHp > b.bonusHp;
}

void wypisz(long long healthMy){
    cout << "moje HP: " << healthMy << endl << "slabe:\n";
    for(int i = 0; i < monsterLittle.size(); i++) cout << "obrazenia: " << monsterLittle[i].damage << "  eliksir: " << monsterLittle[i].bonusHp << endl;
    cout << endl << "boss:\n";
    for(int i = 0; i < monsterBoss.size(); i++) cout << "obrazenia: " << monsterBoss[i].damage << "  eliksir: " << monsterBoss[i].bonusHp << endl;
}

void wypiszKol(long long &mons){
    for(int i = 0; i < mons; i++){
        cout << tab[i] + 1 << " ";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);

    long long mons, healthMy;
    cin >> mons >> healthMy;

    for(int i = 0; i < mons; i++){
        cin >> monster.damage >> monster.bonusHp; monster.number = i;

        if(monster.bonusHp- monster.damage >= 0){
            if(monster.damage >= healthMy){
                monsterLittle.push_back(monster);
            }else {healthMy += monster.bonusHp - monster.damage; tab.push_back(monster.number);}
        }else monsterBoss.push_back(monster);

    }

    sort(monsterLittle.begin(), monsterLittle.end(), comp);
    sort(monsterBoss.begin(), monsterBoss.end(), comp2);

    //wypisz(healthMy);

    for(int i = 0; i < monsterLittle.size(); i++){
        if(healthMy - monsterLittle[i].damage <= 0){ cout << "NIE\n"; return 0; }
        healthMy += monsterLittle[i].bonusHp - monsterLittle[i].damage;
        tab.push_back(monsterLittle[i].number);
    }

    for(int i = 0; i <= monsterBoss.size(); i++){
        if(i == monsterBoss.size()){ cout << "TAK\n"; wypiszKol(mons); break; }
        if(healthMy - monsterBoss[i].damage <= 0){ cout << "NIE\n"; break; }
        healthMy += monsterBoss[i].bonusHp - monsterBoss[i].damage;
        tab.push_back(monsterBoss[i].number);
    }

    return 0;
}
/*
10 7
9 10
3 6
14 15
8 2
7 0
3 9
22 23
4 7
5 4
9 6

10 7
1 3
3 6
6 9
7 2
9 2
7 0
3 9
4 7
5 4
9 6
*/