#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool porownanie(const vector<int>& x,const vector<int>& y)
{
return x[1] < y[1] || (!(y[1] < x[1]) && x[0] < y[0]);
}
main() {
int n, hp, war=0, atak = 10, minb = 10;
cin.sync_with_stdio(false);
cin >> n;
cin >> hp;
vector<vector<int> > tab;
vector<int> tmp;
tmp.resize(3);
for(int i=0; i<n; i++){
cin >> tmp[0] >> tmp[1];
tmp[2] = i;
tab.push_back(tmp);
war = war + tmp[1] - tmp[0];
if(tmp[1] < minb)
minb = tmp[1];
if(tmp[0] < atak)
atak = tmp[0];
}
if(war + hp - abs(minb) <= 0 || atak >= hp) {
cout << "NIE" << endl;
}else{
cout << "TAK" << endl;
sort(tab.begin(),tab.end(),porownanie);
bool tak[n];
int ilosc = 0;
for(int i = 0; i < n; i++)
tak[i] = false;
while(ilosc < n) {
for(int i = n-1; i >= 0; i--) {
if(tak[i] == false && tab[i][0] < hp ) {
tak[i] = true;
cout << tab[i][2]+1 << " ";
hp = hp + tab[i][1] - tab[i][0];
ilosc++;
}}}}}
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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; bool porownanie(const vector<int>& x,const vector<int>& y) { return x[1] < y[1] || (!(y[1] < x[1]) && x[0] < y[0]); } main() { int n, hp, war=0, atak = 10, minb = 10; cin.sync_with_stdio(false); cin >> n; cin >> hp; vector<vector<int> > tab; vector<int> tmp; tmp.resize(3); for(int i=0; i<n; i++){ cin >> tmp[0] >> tmp[1]; tmp[2] = i; tab.push_back(tmp); war = war + tmp[1] - tmp[0]; if(tmp[1] < minb) minb = tmp[1]; if(tmp[0] < atak) atak = tmp[0]; } if(war + hp - abs(minb) <= 0 || atak >= hp) { cout << "NIE" << endl; }else{ cout << "TAK" << endl; sort(tab.begin(),tab.end(),porownanie); bool tak[n]; int ilosc = 0; for(int i = 0; i < n; i++) tak[i] = false; while(ilosc < n) { for(int i = n-1; i >= 0; i--) { if(tak[i] == false && tab[i][0] < hp ) { tak[i] = true; cout << tab[i][2]+1 << " "; hp = hp + tab[i][1] - tab[i][0]; ilosc++; }}}}} |
English