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 <vector>
#include <algorithm>
using namespace std;

class Enemy{
public:
    int damage;
    int elixir;
    int number;
};

bool sg(Enemy l , Enemy p){
    if(l.damage < p.damage)
        return true;
    else
        return false;
}

bool sb(Enemy l , Enemy p){
    if(l.elixir > p.elixir)
        return true;
    else
        return false;
}

int main(){
    int n;
    cin >> n;
    long long power;
    cin >> power;
    Enemy temp;
    vector <Enemy> good;
    vector <Enemy> bad;
    for(int i=0 ; i<n ; i++){
        cin >> temp.damage;
        cin >> temp.elixir;
        temp.number = i+1;
        if(temp.elixir > temp.damage)
            good.push_back(temp);
        else
            bad.push_back(temp);
    }

    sort(good.begin() , good.end() , sg);
    vector <int> odp;
    for(int i=0 ; i<good.size() ; i++){
        if(good[i].damage < power){
            power += good[i].elixir - good[i].damage;
            odp.push_back(good[i].number);
        }
        else{
            cout << "NIE";
            return 0;
        }
    }
    sort(bad.begin() , bad.end() , sb);
    for(int i=0 ; i<bad.size() ; i++){
        if(bad[i].damage < power){
            power += bad[i].elixir - bad[i].damage;
            odp.push_back(bad[i].number);
        }
        else{
            cout << "NIE";
            return 0;
        }
    }

    cout << "TAK" << endl;
    for(int i=0 ; i<n ; i++){
        cout << odp[i] << " ";
    }
}