//BOH #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; struct wrog { int d, a,idx; wrog() {} wrog(int dd, int aa,int id) { d = dd; a = aa; idx = id; } bool operator()(wrog& wa, wrog& wb) { if (wa.d <= wa.d) return true; return false; } bool operator<(wrog& wb) { return d <= wb.d; } }; int main(int, char**) { ios_base::sync_with_stdio(0); vector<wrog> tab; int n, z, d, a, sk, cmax = 1000000; //max -hp cin >> n >> z; sk = z; auto it = tab.begin(); for (int idx = 1; idx <= n;idx++) { cin >> d >> a; sk = sk - d + a; //szybki end tab.push_back(wrog(d, a,idx)); } if (sk < 0) cout << "NIE" << endl; else { //moze pare punktow da :) bool fail = true; while (fail) { int tmpz = z; string kol = ""; fail = false; for (auto w : tab) { tmpz -= w.d; if (tmpz < 0) { fail = true; break; } tmpz += w.a; kol += to_string(w.idx) + " "; } if (fail == false) { cout << "TAK" << endl; cout << kol << endl; break; } next_permutation(tab.begin(), tab.end()); } } 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 | //BOH #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; struct wrog { int d, a,idx; wrog() {} wrog(int dd, int aa,int id) { d = dd; a = aa; idx = id; } bool operator()(wrog& wa, wrog& wb) { if (wa.d <= wa.d) return true; return false; } bool operator<(wrog& wb) { return d <= wb.d; } }; int main(int, char**) { ios_base::sync_with_stdio(0); vector<wrog> tab; int n, z, d, a, sk, cmax = 1000000; //max -hp cin >> n >> z; sk = z; auto it = tab.begin(); for (int idx = 1; idx <= n;idx++) { cin >> d >> a; sk = sk - d + a; //szybki end tab.push_back(wrog(d, a,idx)); } if (sk < 0) cout << "NIE" << endl; else { //moze pare punktow da :) bool fail = true; while (fail) { int tmpz = z; string kol = ""; fail = false; for (auto w : tab) { tmpz -= w.d; if (tmpz < 0) { fail = true; break; } tmpz += w.a; kol += to_string(w.idx) + " "; } if (fail == false) { cout << "TAK" << endl; cout << kol << endl; break; } next_permutation(tab.begin(), tab.end()); } } return 0; } |