#include <iostream> #include <vector> #include <algorithm> using namespace std; struct potwor { long long d, a; }; int main() { ios_base::sync_with_stdio(0); long long n, z; cin >> n >> z; vector<potwor> potwory(n); for (int i = 0; i < n; ++i) cin >> potwory[i].d >> potwory[i].a; vector<int> p(n); for (int i = 0; i < n; ++i) p[i] = i; long long il = 1; for (int i = 2; i <= n; ++i) il *= i; long long koszt; for (int i = 0; i < il; ++i) { koszt = z; int j; for (j = 0; j < n; ++j) { koszt -= potwory[p[j]].d; if (koszt <= 0) break; koszt += potwory[p[j]].a; } if (j == n) { cout << "TAK\n"; for (int k = 0; k < n; ++k) cout << p[k] + 1 << " "; return 0; } next_permutation(p.begin(), p.end()); } cout << "NIE\n"; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; struct potwor { long long d, a; }; int main() { ios_base::sync_with_stdio(0); long long n, z; cin >> n >> z; vector<potwor> potwory(n); for (int i = 0; i < n; ++i) cin >> potwory[i].d >> potwory[i].a; vector<int> p(n); for (int i = 0; i < n; ++i) p[i] = i; long long il = 1; for (int i = 2; i <= n; ++i) il *= i; long long koszt; for (int i = 0; i < il; ++i) { koszt = z; int j; for (j = 0; j < n; ++j) { koszt -= potwory[p[j]].d; if (koszt <= 0) break; koszt += potwory[p[j]].a; } if (j == n) { cout << "TAK\n"; for (int k = 0; k < n; ++k) cout << p[k] + 1 << " "; return 0; } next_permutation(p.begin(), p.end()); } cout << "NIE\n"; return 0; } |