#include <list>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#include <stdlib.h>
#include <sstream>
#include <queue>
using namespace std;
int main() {
int n, strongest=0;
double hp, dmg, pot, hold0, hold1, hold2, hold3;
cin >> n;
cin >> hp;
int licznik=0, count=0;
ostringstream ss;
queue<int>pozytyw;
double negatyw[4][n];
int negcount=0;
for (int i=0; i<n; i++){
licznik++;
cin >> dmg;
cin >> pot;
if(hp>dmg){ // jezeli moze pokonac to
if(pot>=dmg){ //zabija jesli sie nic nie traci
ss<<" "<<licznik;
hp=hp-dmg+pot;
}else{
negatyw[0][negcount]=licznik;
negatyw[1][negcount]=dmg;
negatyw[2][negcount]=pot;
negatyw[3][negcount]=pot/dmg;
negcount++;
}
}
else if(pot>=dmg){ //jezeli nie moze pokonac a jest korzystny
pozytyw.push(licznik);
pozytyw.push(dmg);
pozytyw.push(pot);
}
else{ //jest NIEkorzystnyNIE
negatyw[0][negcount]=licznik;
negatyw[1][negcount]=dmg;
negatyw[2][negcount]=pot;
negatyw[3][negcount]=pot/dmg;
negcount++;
}
}
//koniec wstepnego sortowania
while(count<pozytyw.size()){ //zjadanie pozytywow
licznik=pozytyw.front();
pozytyw.pop();
dmg=pozytyw.front();
pozytyw.pop();
pot=pozytyw.front();
pozytyw.pop();
if(hp>dmg){
ss<<licznik;
hp=hp-dmg+pot;
count=0;
}else{
pozytyw.push(licznik);
pozytyw.push(hp);
pozytyw.push(dmg);
count++;
}
}
if(pozytyw.empty()){}else{cout<<"NIE"; return 0;}
//koniec zjadania pozytywow
for(int z=0;z<negcount;z++){ //licznik bydlakow
if(negatyw[1][z]>strongest){
strongest=dmg;
}
}
if(hp<=strongest){cout<<"NIE"; return 0;}
int vec[negcount];
for(int z=0;z<negcount;z++){vec[z]=z;}
//przygotowanie przestrzeni permutacji
do {
int temphp=hp;
for(int z=0;z<negcount;z++) {
temphp-=negatyw[1][vec[z]]; //jazda po permutacjach!!!
if(temphp<=0){break;}
temphp+=negatyw[2][vec[z]];
}
if(temphp>0){
for(int z=0;z<negcount;z++){
ss<<" "<<negatyw[0][vec[z]];}
cout<<"TAK\n"<<ss.str();
return 0;
}
} while ( next_permutation(vec,vec+negcount) );
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include <list> #include <iostream> #include <math.h> #include <algorithm> #include <iterator> #include <vector> #include <string> #include <stdlib.h> #include <sstream> #include <queue> using namespace std; int main() { int n, strongest=0; double hp, dmg, pot, hold0, hold1, hold2, hold3; cin >> n; cin >> hp; int licznik=0, count=0; ostringstream ss; queue<int>pozytyw; double negatyw[4][n]; int negcount=0; for (int i=0; i<n; i++){ licznik++; cin >> dmg; cin >> pot; if(hp>dmg){ // jezeli moze pokonac to if(pot>=dmg){ //zabija jesli sie nic nie traci ss<<" "<<licznik; hp=hp-dmg+pot; }else{ negatyw[0][negcount]=licznik; negatyw[1][negcount]=dmg; negatyw[2][negcount]=pot; negatyw[3][negcount]=pot/dmg; negcount++; } } else if(pot>=dmg){ //jezeli nie moze pokonac a jest korzystny pozytyw.push(licznik); pozytyw.push(dmg); pozytyw.push(pot); } else{ //jest NIEkorzystnyNIE negatyw[0][negcount]=licznik; negatyw[1][negcount]=dmg; negatyw[2][negcount]=pot; negatyw[3][negcount]=pot/dmg; negcount++; } } //koniec wstepnego sortowania while(count<pozytyw.size()){ //zjadanie pozytywow licznik=pozytyw.front(); pozytyw.pop(); dmg=pozytyw.front(); pozytyw.pop(); pot=pozytyw.front(); pozytyw.pop(); if(hp>dmg){ ss<<licznik; hp=hp-dmg+pot; count=0; }else{ pozytyw.push(licznik); pozytyw.push(hp); pozytyw.push(dmg); count++; } } if(pozytyw.empty()){}else{cout<<"NIE"; return 0;} //koniec zjadania pozytywow for(int z=0;z<negcount;z++){ //licznik bydlakow if(negatyw[1][z]>strongest){ strongest=dmg; } } if(hp<=strongest){cout<<"NIE"; return 0;} int vec[negcount]; for(int z=0;z<negcount;z++){vec[z]=z;} //przygotowanie przestrzeni permutacji do { int temphp=hp; for(int z=0;z<negcount;z++) { temphp-=negatyw[1][vec[z]]; //jazda po permutacjach!!! if(temphp<=0){break;} temphp+=negatyw[2][vec[z]]; } if(temphp>0){ for(int z=0;z<negcount;z++){ ss<<" "<<negatyw[0][vec[z]];} cout<<"TAK\n"<<ss.str(); return 0; } } while ( next_permutation(vec,vec+negcount) ); return 0; } |
English