#include <iostream> #include <queue> using namespace std; // Tworzenie tablic przechowujacych dane struct struktura{ int damage; int heal; int id; }; struktura good[100000] = {0}; struktura bad[100000] = {0}; int nGoodCount = 0; int nBadCount = 0; int tmp = 0; void Stupid_Sort_good(int lewy, int prawy) { // Inty jakies int i,j,piwot1,piwot2,piwot3; i = (lewy + prawy) / 2; piwot1 = good[i].damage; piwot2 = good[i].heal; piwot3 = good[i].id; good[i].damage = good[prawy].damage; good[i].heal = good[prawy].heal; good[i].id = good[prawy].id; for(j = i = lewy; i < prawy; i++) if(good[i].damage < piwot1) { tmp = good[i].damage; good[i].damage = good[j].damage; good[j].damage = tmp; tmp = good[i].heal; good[i].heal = good[j].heal; good[j].heal = tmp; tmp = good[i].id; good[i].id = good[j].id; good[j].id = tmp; j++; } good[prawy].damage = good[j].damage; good[prawy].heal = good[j].heal; good[prawy].id = good[j].id; good[j].damage = piwot1; good[j].heal = piwot2; good[j].id = piwot3; if(lewy < j - 1) Stupid_Sort_good(lewy, j - 1); if(j + 1 < prawy) Stupid_Sort_good(j + 1, prawy); } void Stupid_Sort_bad(int lewy, int prawy) { // Inty jakies int i,j,piwot1,piwot2,piwot3; i = (lewy + prawy) / 2; piwot1 = bad[i].damage; piwot2 = bad[i].heal; piwot3 = bad[i].id; bad[i].damage = bad[prawy].damage; bad[i].heal = bad[prawy].heal; bad[i].id = bad[prawy].id; for(j = i = lewy; i < prawy; i++) if(bad[i].heal > piwot2) { tmp = bad[i].damage; bad[i].damage = bad[j].damage; bad[j].damage = tmp; tmp = bad[i].heal; bad[i].heal = bad[j].heal; bad[j].heal = tmp; tmp = bad[i].id; bad[i].id = bad[j].id; bad[j].id = tmp; j++; } bad[prawy].damage = bad[j].damage; bad[prawy].heal = bad[j].heal; bad[prawy].id = bad[j].id; bad[j].damage = piwot1; bad[j].heal = piwot2; bad[j].id = piwot3; if(lewy < j - 1) Stupid_Sort_bad(lewy, j - 1); if(j + 1 < prawy) Stupid_Sort_bad(j + 1, prawy); } void Stupid_Sort_bad_dmg(int lewy, int prawy) { // Inty jakies int i,j,piwot1,piwot2,piwot3; i = (lewy + prawy) / 2; piwot1 = bad[i].damage; piwot2 = bad[i].heal; piwot3 = bad[i].id; bad[i].damage = bad[prawy].damage; bad[i].heal = bad[prawy].heal; bad[i].id = bad[prawy].id; for(j = i = lewy; i < prawy; i++) if(bad[i].damage > piwot1) { tmp = bad[i].damage; bad[i].damage = bad[j].damage; bad[j].damage = tmp; tmp = bad[i].heal; bad[i].heal = bad[j].heal; bad[j].heal = tmp; tmp = bad[i].id; bad[i].id = bad[j].id; bad[j].id = tmp; j++; } bad[prawy].damage = bad[j].damage; bad[prawy].heal = bad[j].heal; bad[prawy].id = bad[j].id; bad[j].damage = piwot1; bad[j].heal = piwot2; bad[j].id = piwot3; if(lewy < j - 1) Stupid_Sort_bad_dmg(lewy, j - 1); if(j + 1 < prawy) Stupid_Sort_bad_dmg(j + 1, prawy); } int main() { ios_base::sync_with_stdio(0); // Pobieranie ilosci mobow i ilosci hp int nIloscMobow; int nIloscHp; cin>>nIloscMobow>>nIloscHp; int nDamageTmp; int nHealTmp; // Rozdzielanie informacji for(int x = 0; x < nIloscMobow; x++) { cin>>nDamageTmp>>nHealTmp; if (nDamageTmp <= nHealTmp) { // Korzystne good[nGoodCount].damage = nDamageTmp; good[nGoodCount].heal = nHealTmp; good[nGoodCount].id = x + 1; nGoodCount++; } else { // Niekozystne bad[nBadCount].damage = nDamageTmp; bad[nBadCount].heal = nHealTmp; bad[nBadCount].id = x + 1; nBadCount++; } } // Tworzenie kolejki kolejnosci mobow queue <int> nKolejnoscMobow; // Sortowanie dobrych Stupid_Sort_good(0,nGoodCount - 1); // Sortowanie zlych Stupid_Sort_bad(0,nBadCount - 1); // Sortowanie yolo int pocz = 0; int actual = bad[0].heal; for(int x = 1; x < nBadCount; x++) { if (bad[x].heal != actual) { if (pocz < x - 1) Stupid_Sort_bad_dmg(pocz,x - 1); actual = bad[x].heal; pocz = x; } } // Liczenie kolejnosci // Najpierw dobre for (int x = 0; x < nGoodCount; x++) { if (good[x].damage < nIloscHp) { nIloscHp -= good[x].damage; nIloscHp += good[x].heal; nKolejnoscMobow.push(good[x].id); } else { cout<<"NIE"; return 0; } } // Potem te zle for (int x = 0; x < nBadCount; x++) { if (bad[x].damage < nIloscHp) { nIloscHp -= bad[x].damage; nIloscHp += bad[x].heal; nKolejnoscMobow.push(bad[x].id); } else { cout<<"NIE"; return 0; } } // A na koncu wyswietlanie ze sie da cout<<"TAK"<<endl; while(!nKolejnoscMobow.empty()) { cout<<nKolejnoscMobow.front()<<" "; nKolejnoscMobow.pop(); } 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | #include <iostream> #include <queue> using namespace std; // Tworzenie tablic przechowujacych dane struct struktura{ int damage; int heal; int id; }; struktura good[100000] = {0}; struktura bad[100000] = {0}; int nGoodCount = 0; int nBadCount = 0; int tmp = 0; void Stupid_Sort_good(int lewy, int prawy) { // Inty jakies int i,j,piwot1,piwot2,piwot3; i = (lewy + prawy) / 2; piwot1 = good[i].damage; piwot2 = good[i].heal; piwot3 = good[i].id; good[i].damage = good[prawy].damage; good[i].heal = good[prawy].heal; good[i].id = good[prawy].id; for(j = i = lewy; i < prawy; i++) if(good[i].damage < piwot1) { tmp = good[i].damage; good[i].damage = good[j].damage; good[j].damage = tmp; tmp = good[i].heal; good[i].heal = good[j].heal; good[j].heal = tmp; tmp = good[i].id; good[i].id = good[j].id; good[j].id = tmp; j++; } good[prawy].damage = good[j].damage; good[prawy].heal = good[j].heal; good[prawy].id = good[j].id; good[j].damage = piwot1; good[j].heal = piwot2; good[j].id = piwot3; if(lewy < j - 1) Stupid_Sort_good(lewy, j - 1); if(j + 1 < prawy) Stupid_Sort_good(j + 1, prawy); } void Stupid_Sort_bad(int lewy, int prawy) { // Inty jakies int i,j,piwot1,piwot2,piwot3; i = (lewy + prawy) / 2; piwot1 = bad[i].damage; piwot2 = bad[i].heal; piwot3 = bad[i].id; bad[i].damage = bad[prawy].damage; bad[i].heal = bad[prawy].heal; bad[i].id = bad[prawy].id; for(j = i = lewy; i < prawy; i++) if(bad[i].heal > piwot2) { tmp = bad[i].damage; bad[i].damage = bad[j].damage; bad[j].damage = tmp; tmp = bad[i].heal; bad[i].heal = bad[j].heal; bad[j].heal = tmp; tmp = bad[i].id; bad[i].id = bad[j].id; bad[j].id = tmp; j++; } bad[prawy].damage = bad[j].damage; bad[prawy].heal = bad[j].heal; bad[prawy].id = bad[j].id; bad[j].damage = piwot1; bad[j].heal = piwot2; bad[j].id = piwot3; if(lewy < j - 1) Stupid_Sort_bad(lewy, j - 1); if(j + 1 < prawy) Stupid_Sort_bad(j + 1, prawy); } void Stupid_Sort_bad_dmg(int lewy, int prawy) { // Inty jakies int i,j,piwot1,piwot2,piwot3; i = (lewy + prawy) / 2; piwot1 = bad[i].damage; piwot2 = bad[i].heal; piwot3 = bad[i].id; bad[i].damage = bad[prawy].damage; bad[i].heal = bad[prawy].heal; bad[i].id = bad[prawy].id; for(j = i = lewy; i < prawy; i++) if(bad[i].damage > piwot1) { tmp = bad[i].damage; bad[i].damage = bad[j].damage; bad[j].damage = tmp; tmp = bad[i].heal; bad[i].heal = bad[j].heal; bad[j].heal = tmp; tmp = bad[i].id; bad[i].id = bad[j].id; bad[j].id = tmp; j++; } bad[prawy].damage = bad[j].damage; bad[prawy].heal = bad[j].heal; bad[prawy].id = bad[j].id; bad[j].damage = piwot1; bad[j].heal = piwot2; bad[j].id = piwot3; if(lewy < j - 1) Stupid_Sort_bad_dmg(lewy, j - 1); if(j + 1 < prawy) Stupid_Sort_bad_dmg(j + 1, prawy); } int main() { ios_base::sync_with_stdio(0); // Pobieranie ilosci mobow i ilosci hp int nIloscMobow; int nIloscHp; cin>>nIloscMobow>>nIloscHp; int nDamageTmp; int nHealTmp; // Rozdzielanie informacji for(int x = 0; x < nIloscMobow; x++) { cin>>nDamageTmp>>nHealTmp; if (nDamageTmp <= nHealTmp) { // Korzystne good[nGoodCount].damage = nDamageTmp; good[nGoodCount].heal = nHealTmp; good[nGoodCount].id = x + 1; nGoodCount++; } else { // Niekozystne bad[nBadCount].damage = nDamageTmp; bad[nBadCount].heal = nHealTmp; bad[nBadCount].id = x + 1; nBadCount++; } } // Tworzenie kolejki kolejnosci mobow queue <int> nKolejnoscMobow; // Sortowanie dobrych Stupid_Sort_good(0,nGoodCount - 1); // Sortowanie zlych Stupid_Sort_bad(0,nBadCount - 1); // Sortowanie yolo int pocz = 0; int actual = bad[0].heal; for(int x = 1; x < nBadCount; x++) { if (bad[x].heal != actual) { if (pocz < x - 1) Stupid_Sort_bad_dmg(pocz,x - 1); actual = bad[x].heal; pocz = x; } } // Liczenie kolejnosci // Najpierw dobre for (int x = 0; x < nGoodCount; x++) { if (good[x].damage < nIloscHp) { nIloscHp -= good[x].damage; nIloscHp += good[x].heal; nKolejnoscMobow.push(good[x].id); } else { cout<<"NIE"; return 0; } } // Potem te zle for (int x = 0; x < nBadCount; x++) { if (bad[x].damage < nIloscHp) { nIloscHp -= bad[x].damage; nIloscHp += bad[x].heal; nKolejnoscMobow.push(bad[x].id); } else { cout<<"NIE"; return 0; } } // A na koncu wyswietlanie ze sie da cout<<"TAK"<<endl; while(!nKolejnoscMobow.empty()) { cout<<nKolejnoscMobow.front()<<" "; nKolejnoscMobow.pop(); } return 0; } |