#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
int main()
{
int n, hp, a, b;
bool spr=1;
pair<pair<int,int>, int> t;
vector<pair<pair<int,int>, int> > pdane, mdane;
cin>>n>>hp;
int hpk=hp;
for(int i=0; i<n; i++){
cin>>a>>b;
hpk-=a-b;
if(a<b){
t=make_pair(make_pair(a,b), i+1);
pdane.push_back(t);
}
else{
t=make_pair(make_pair(b,a), i+1);
mdane.push_back(t);
}
}
if(hpk<=0){ spr=0; cout<<"NIE"; }
else{
sort(pdane.begin(), pdane.end());
sort(mdane.begin(), mdane.end());
}
vector<int> wynik(n);
if(spr){
for(int i=0; i<pdane.size(); i++){
if(pdane[i].first.first<hp){
hp-=pdane[i].first.first - pdane[i].first.second;
wynik[i]=pdane[i].second;
}
else { spr=0; cout<<"NIE"; break; }
}
}
if(spr){
for(int i=0; i<mdane.size(); i++){
if(mdane[i].first.first<hpk){
hpk-=mdane[i].first.first - mdane[i].first.second;
wynik[n-i-1]=mdane[i].second;
}
else { spr=0; cout<<"NIE"; break; }
}
}
if(spr){
cout<<"TAK"<<endl;
for(int i=0; i<n; i++)
cout<<wynik[i]<<" ";
}
}
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 <vector> #include <list> #include <algorithm> using namespace std; int main() { int n, hp, a, b; bool spr=1; pair<pair<int,int>, int> t; vector<pair<pair<int,int>, int> > pdane, mdane; cin>>n>>hp; int hpk=hp; for(int i=0; i<n; i++){ cin>>a>>b; hpk-=a-b; if(a<b){ t=make_pair(make_pair(a,b), i+1); pdane.push_back(t); } else{ t=make_pair(make_pair(b,a), i+1); mdane.push_back(t); } } if(hpk<=0){ spr=0; cout<<"NIE"; } else{ sort(pdane.begin(), pdane.end()); sort(mdane.begin(), mdane.end()); } vector<int> wynik(n); if(spr){ for(int i=0; i<pdane.size(); i++){ if(pdane[i].first.first<hp){ hp-=pdane[i].first.first - pdane[i].first.second; wynik[i]=pdane[i].second; } else { spr=0; cout<<"NIE"; break; } } } if(spr){ for(int i=0; i<mdane.size(); i++){ if(mdane[i].first.first<hpk){ hpk-=mdane[i].first.first - mdane[i].first.second; wynik[n-i-1]=mdane[i].second; } else { spr=0; cout<<"NIE"; break; } } } if(spr){ cout<<"TAK"<<endl; for(int i=0; i<n; i++) cout<<wynik[i]<<" "; } } |
polski