#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
struct potwr{
long poz;
long dmg;
long pot;
};
bool comp(potwr a, potwr b) { return (a.pot > b.pot);}
int main(int argc, char **argv) {
long long hp;
long n;
long wyn[100001];
std::vector<potwr> tab[100001];
std::ios::sync_with_stdio(false);
std::cin >> n >> hp;
for(long i = 1; i<=n; ++i){
potwr * monstr = new potwr();
std::cin >> monstr->dmg >> monstr->pot;
monstr->poz = i;
tab[monstr->dmg].push_back(*monstr);
}
for(long i = 1; i<=100000; ++i){
std::sort(tab[i].begin(),tab[i].end(),comp);
}
bool czy = true;
for(long i = 1; i<=n; ++i){
long poz = 100000;
if(hp<100000) poz = hp - 1;
while(poz > 0 && tab[poz].empty()) poz--;
if(poz==0){
czy = false;
break;
}
hp-=tab[poz].front().dmg;
hp+=tab[poz].front().pot;
wyn[i] = tab[poz].front().poz;
tab[poz].erase(tab[poz].begin());
}
if(czy){
std::cout << "TAK" << std::endl;
for(long i = 1; i<n; ++i){
std::cout << wyn[i] << ' ';
}
std::cout << wyn[n] << std::endl;
} else {
std::cout << "NIE" <<std::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 | #include <iostream> #include <vector> #include <algorithm> #include <string> struct potwr{ long poz; long dmg; long pot; }; bool comp(potwr a, potwr b) { return (a.pot > b.pot);} int main(int argc, char **argv) { long long hp; long n; long wyn[100001]; std::vector<potwr> tab[100001]; std::ios::sync_with_stdio(false); std::cin >> n >> hp; for(long i = 1; i<=n; ++i){ potwr * monstr = new potwr(); std::cin >> monstr->dmg >> monstr->pot; monstr->poz = i; tab[monstr->dmg].push_back(*monstr); } for(long i = 1; i<=100000; ++i){ std::sort(tab[i].begin(),tab[i].end(),comp); } bool czy = true; for(long i = 1; i<=n; ++i){ long poz = 100000; if(hp<100000) poz = hp - 1; while(poz > 0 && tab[poz].empty()) poz--; if(poz==0){ czy = false; break; } hp-=tab[poz].front().dmg; hp+=tab[poz].front().pot; wyn[i] = tab[poz].front().poz; tab[poz].erase(tab[poz].begin()); } if(czy){ std::cout << "TAK" << std::endl; for(long i = 1; i<n; ++i){ std::cout << wyn[i] << ' '; } std::cout << wyn[n] << std::endl; } else { std::cout << "NIE" <<std::endl; } return 0; } |
English