#include <iostream>
#include <algorithm>
using namespace std;
int M;
long long HP;
struct xxx{
int first, second, index;
}m[100009];//first - obrazenia; second - leczenie
bool odp=true;
bool cmp(xxx a, xxx b){
if(a.second>=a.first && b.second>=b.first)
return a.first < b.first;
if(a.second>=a.first)
return true;
if(b.second>=b.first)
return false;
return a.second > b.second;
}
int main(){
ios_base::sync_with_stdio(0);
cin>>M>>HP;
for(int i=0; i<M; i++){
cin>>m[i].first>>m[i].second;
m[i].index=i+1;
}
sort(m, m+M, cmp);
for(int i=0; i<M; i++){
HP-=m[i].first;
if(HP<=0)
odp=false;
HP+=m[i].second;
}
if(odp){
cout<<"TAK\n";
for(int i=0; i<M; i++)
cout<<m[i].index<<" ";
}
else
cout<<"NIE\n";
return 0;
}
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 | #include <iostream> #include <algorithm> using namespace std; int M; long long HP; struct xxx{ int first, second, index; }m[100009];//first - obrazenia; second - leczenie bool odp=true; bool cmp(xxx a, xxx b){ if(a.second>=a.first && b.second>=b.first) return a.first < b.first; if(a.second>=a.first) return true; if(b.second>=b.first) return false; return a.second > b.second; } int main(){ ios_base::sync_with_stdio(0); cin>>M>>HP; for(int i=0; i<M; i++){ cin>>m[i].first>>m[i].second; m[i].index=i+1; } sort(m, m+M, cmp); for(int i=0; i<M; i++){ HP-=m[i].first; if(HP<=0) odp=false; HP+=m[i].second; } if(odp){ cout<<"TAK\n"; for(int i=0; i<M; i++) cout<<m[i].index<<" "; } else cout<<"NIE\n"; return 0; } |
English