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>
using namespace std;
#define repeat(a) for(int i=0;i<a;i++)

struct potwor{
int nr
,dmg //obrazenia
,potion;//elisir
};

potwor tab1[100001],tab2[100001];

bool compare(potwor a,potwor b)
{
    return a.dmg<b.dmg;
}
bool compare1(potwor a,potwor b)
{
    return a.potion>b.potion;
}
int main(){

ios_base::sync_with_stdio(0);
potwor a;
long long lpotw,health,licz1=0,licz2=0,roznica;
cin>>lpotw>>health;

repeat(lpotw)
{
    cin>>a.dmg>>a.potion;
   a.nr=i+1;
   roznica=a.potion-a.dmg;
  if(roznica>=0)
    {tab1[licz1]=a;licz1++;}
  else{tab2[licz2]=a;licz2++;}

}
sort(tab1,tab1+licz1,compare);//sort po obrazeniach
sort(tab2,tab2+licz2,compare1);//sort po elisirach

repeat(licz1)
if(health-tab1[i].dmg<=0){cout<<"NIE"; return 0;}
else health=health-tab1[i].dmg+tab1[i].potion;

repeat(licz2)
if(health-tab2[i].dmg<=0){cout<<"NIE"; return 0;}
else health=health-tab2[i].dmg+tab2[i].potion;

cout<<"TAK"<<endl;
repeat(licz1)cout<<tab1[i].nr<<" ";
repeat(licz2)cout<<tab2[i].nr<<" ";
return 0;

}