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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Monster{
	int att;
	int bilans;
	int floor;
};
int main(){
	ios_base::sync_with_stdio(0);
	int n,z; //n-ile potworkow z-zycie
	cin>>n>>z;
	vector<Monster> data;
	Monster temp;
	int check=z;
	int attack,heal;
	for(int i=0;i<n;i++){
		cin>>attack>>heal;
		temp.att=attack;
		temp.bilans=heal-attack;
		temp.floor=i+1;
		check+=temp.bilans;
		data.push_back(temp);
	}
	if(check<=0){
		cout<<"NIE";
	}else{
		stable_sort(data.begin(), data.end(), [](Monster const &a, Monster const &b){ return a.bilans > b.bilans; });
		int ok,j(0),sciezka[n];
		do{
			ok=0;
			for (int i=0;i <data.size(); i++){
				if(z-data[i].att>0){
					z+=data[i].bilans;
					ok=1;
					sciezka[j]=data[i].floor;
					j++;
					data.erase(data.begin()+i);
					break;
				}
				}
				
		}while(ok==1);
		if(j==n){
			cout<<"TAK"<<endl;
			for(int i=0;i<n;i++){
				cout<<sciezka[i]<<" ";
			}
		}else{
			cout<<"NIE";
		}
		}
	return 0;
}