#include <iostream> using namespace std; int main() {ios_base::sync_with_stdio(0); int t, hp, p, hp1 = 0, licz =1; cin >> t >> hp; int tab[t], tabhp[t], tabwyn[t]; for(int i = 0; i < t; i++) { cin >> tab[i] >> tabhp[i]; tabwyn[i] = 0; } for(int i = 0; i < t; i++) {for(int j = 0; j < t; j++) { if(tab[j] != -1) { if((hp - tab[j] > 0)) { if(hp - tab[j] + tabhp[j] > hp1) { hp1 = hp - tab[j] + tabhp[j]; tabwyn[i] = j+1; } } } } if(tabwyn[i]==0) {cout << "NIE\n"; licz = 0; break;} hp = hp1; hp1 = 0; // cout << tabwyn[i] << endl; tab[tabwyn[i]-1] = -1; } if(licz!=0){ cout << "TAK\n"; for(int i = 0 ; i < t; i++) cout << tabwyn[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 | #include <iostream> using namespace std; int main() {ios_base::sync_with_stdio(0); int t, hp, p, hp1 = 0, licz =1; cin >> t >> hp; int tab[t], tabhp[t], tabwyn[t]; for(int i = 0; i < t; i++) { cin >> tab[i] >> tabhp[i]; tabwyn[i] = 0; } for(int i = 0; i < t; i++) {for(int j = 0; j < t; j++) { if(tab[j] != -1) { if((hp - tab[j] > 0)) { if(hp - tab[j] + tabhp[j] > hp1) { hp1 = hp - tab[j] + tabhp[j]; tabwyn[i] = j+1; } } } } if(tabwyn[i]==0) {cout << "NIE\n"; licz = 0; break;} hp = hp1; hp1 = 0; // cout << tabwyn[i] << endl; tab[tabwyn[i]-1] = -1; } if(licz!=0){ cout << "TAK\n"; for(int i = 0 ; i < t; i++) cout << tabwyn[i] << " "; } } |