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

struct para{
    int first; int second; int id;
};

vector < para > plusy;
vector < para > minusy;
vector < int > path;

int n, hp;

para tmp;

bool ros(para i, para j){ return i.first <j.first;}
bool mal(para i, para j){ return i.first >j.first;}

int main() {
    ios_base::sync_with_stdio(0);
	cin>>n>>hp;
	for(int i =0; i<n; i++){
		cin>>tmp.first>>tmp.second;
        tmp.id=i+1;
        
		if (tmp.second-tmp.first>=0) {
            plusy.push_back(tmp);
        }
        else minusy.push_back(tmp);
	}
	sort(plusy.begin(), plusy.end(),ros);
    sort(minusy.begin(), minusy.end(), mal);
    
    bool wentyl =false;
    for(int i =0; i<plusy.size(); i++){
        path.push_back(plusy[i].id);
        if (hp-plusy[i].first<=0) {
            wentyl = true;
        }
        hp+=plusy[i].second - plusy[i].first;
    }
    for(int i =0; i<minusy.size(); i++){
        path.push_back(minusy[i].id);
        if (hp-minusy[i].first<=0) {
            wentyl = true;
        }
        hp+=minusy[i].second - minusy[i].first;
    }
    //cout<<hp<<endl;
    if(hp>0 && !wentyl){
        cout<<"TAK"<<endl;
        for(int i =0; i<path.size(); i++){
            cout<<path[i]<<" ";
        }
    }
    else cout<<"NIE"<<endl;
	return 0;
}