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

using namespace std;

typedef vector<int> v_i;
typedef vector<v_i> vv_i;

bool comp(v_i a, v_i b){
    int da = a[1] - a[0];
    int db = b[1] - b[0];
    if (da >= 0 && db >= 0) return a[0] < b[0];
    if (da >= 0 && db <  0) return true;
    if (da <  0 && db >= 0) return false;
    if (da <  0 && db <  0) return a[0] > b[0];
}

int main(){
    ios_base::sync_with_stdio(0);
    int n, hp0, temp;
    vv_i a; 
    cin>>n>>hp0;
    for(int i=0;i<n;i++){
        v_i temp2;
        cin>>temp;
        temp2.push_back(temp);
        cin>>temp;
        temp2.push_back(temp);
        temp2.push_back(i);
        a.push_back(temp2);
    }
    stable_sort(a.begin(), a.end(), comp);
    for(int i=0;i<n;i++){
        hp0 -= a[i][0];
        if(hp0 <= 0){
            cout<<"NIE"<<endl;
            return 0;
        }
        hp0 += a[i][1];
    }
    cout<<"TAK"<<endl;
    for(int i=0;i<n-1;i++){
        cout<<a[i][2]+1<<" ";
    }
    cout<<a[n-1][2]+1<<endl;
    return 0;
}