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

using namespace std;

pair<int, int>tab[100100];
pair<int, int>tab1[100100];
vector<int>tab2;

int main(){

int n,z;
cin >> n >> z;

for(int i=0;i<n;i++){
cin >> tab[i]. first >> tab[i].second;
tab[i].second = tab[i].second - tab[i].first;
tab1[i].first = tab[i].first;
tab1[i].second = i;
}

sort(tab,tab+n);
sort(tab1,tab1+n);

for(int i=0;i<n;i++){
if(tab[i].second >= 0){
if(z > tab[i].first){
z = z + tab[i].second;
tab2.push_back(tab1[i].second);
}
}
}

for(int i=n-1;i>=0;i--){
if(tab[i].second < 0){
if(z > tab[i].first){
z = z + tab[i].second;
tab2.push_back(tab1[i].second);
}
}
}


if(tab2.size() != n)
    cout << "NIE";

else{
    cout << "TAK" << endl;

    for(int i=0;i<n;i++)
        cout<< tab2[i] + 1 << ' ';
}


return 0;
}