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

bool live;
long long N,Z,HP,damage,potion;
priority_queue <pair<pair<long long,long long>,long long> > dodatni;
priority_queue <pair<pair<long long,long long>,long long> > ujemny;
queue <long long> enemies;

void read(){
cin >> N >> Z;
HP = Z;
live = true;
for(long long i=1;i<=N;i++){
    cin >> damage >> potion;
    if(potion>damage){
        dodatni.push(make_pair(make_pair(-damage,potion), i));
    }
    else {
         ujemny.push(make_pair(make_pair(potion,-damage), i));
    }
}}

void Pain_Train(){
while(dodatni.size()!=0){
    HP+=dodatni.top().first.first;
    if(HP<=0)live = false;
    HP+=dodatni.top().first.second;
    enemies.push(dodatni.top().second);
    dodatni.pop();
}
while(ujemny.size()!=0){
    HP+=ujemny.top().first.second;
    if(HP<=0)live = false;
    HP+=ujemny.top().first.first;
    enemies.push(ujemny.top().second);
    ujemny.pop();
}
if(live == true){
    cout << "TAK" << "\n";
    while(enemies.size()!=0){
            cout << enemies.front() << " ";
            enemies.pop();
}
cout << "\n";
}
else cout << "NIE" << "\n";
}

int main(){
ios_base::sync_with_stdio(0);
read();
Pain_Train();
return 0;
}