#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; main() { ios_base::sync_with_stdio(0); vector <pair<int,int > > potworki; vector <pair<pair<int,int>, int > > potworkizbytdobre; queue < int > kolejka; int n, hp, damage, pot; cin>>n>>hp; int m=n, d=0; for(int i=0;i<n;i++) { cin>>damage>>pot; if(pot>=damage) { if(hp>damage) { hp=hp+pot-damage; kolejka.push(i+1); m--; } else { // tu dodac potworkizbytdobre.push_back(make_pair ( make_pair(damage,pot), i+1 ) ); m--; d++; } } else potworki.push_back(make_pair(pot-damage,i+1)); } sort(potworkizbytdobre.begin(), potworkizbytdobre.end()); for(int i=0;i<d;i++) { if(potworkizbytdobre[i].first.first<hp) { hp=hp+potworkizbytdobre[i].first.second-potworkizbytdobre[i].first.first; kolejka.push(potworkizbytdobre[i].second); } else { cout<<"NIE"<<endl; return 0; } } sort(potworki.begin(), potworki.end()); for(int i=0;i<m;i++) { if(hp+potworki[i].first>0) kolejka.push(potworki[i].second); else { cout<<"NIE"<<endl; return 0; } } cout<<"TAK"<<endl; while( kolejka.empty() == false ) { cout<<kolejka.front()<<" "; kolejka.pop(); } cout<<endl; 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; main() { ios_base::sync_with_stdio(0); vector <pair<int,int > > potworki; vector <pair<pair<int,int>, int > > potworkizbytdobre; queue < int > kolejka; int n, hp, damage, pot; cin>>n>>hp; int m=n, d=0; for(int i=0;i<n;i++) { cin>>damage>>pot; if(pot>=damage) { if(hp>damage) { hp=hp+pot-damage; kolejka.push(i+1); m--; } else { // tu dodac potworkizbytdobre.push_back(make_pair ( make_pair(damage,pot), i+1 ) ); m--; d++; } } else potworki.push_back(make_pair(pot-damage,i+1)); } sort(potworkizbytdobre.begin(), potworkizbytdobre.end()); for(int i=0;i<d;i++) { if(potworkizbytdobre[i].first.first<hp) { hp=hp+potworkizbytdobre[i].first.second-potworkizbytdobre[i].first.first; kolejka.push(potworkizbytdobre[i].second); } else { cout<<"NIE"<<endl; return 0; } } sort(potworki.begin(), potworki.end()); for(int i=0;i<m;i++) { if(hp+potworki[i].first>0) kolejka.push(potworki[i].second); else { cout<<"NIE"<<endl; return 0; } } cout<<"TAK"<<endl; while( kolejka.empty() == false ) { cout<<kolejka.front()<<" "; kolejka.pop(); } cout<<endl; return 0; } |