#include <algorithm> #include <iostream> #include <tuple> #include <vector> using namespace std; namespace { struct enemy { int limit; int delta; int id; enemy() = default; enemy(int limit_, int delta_, int id_): limit(limit_), delta(delta_), id(id_) {} }; vector<int> solve(vector<enemy> data, long long hp) { auto cmp = [](enemy const& a, enemy const& b) { if (a.delta >= 0 && b.delta < 0) return true; if (a.delta < 0 && b.delta >= 0) return false; if (a.delta >= 0) { return a.limit < b.limit; } else { return a.limit + a.delta > b.limit + b.delta; } }; sort(data.begin(), data.end(), cmp); vector<int> res; res.reserve(data.size()); for (auto const& e: data) { if (hp < e.limit) return {}; hp += e.delta; res.push_back(e.id); } return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(NULL); int n, z; cin >> n >> z; vector<enemy> data; data.reserve(n); for (int i = 0; i < n; ++i) { int d, a; cin >> d >> a; data.emplace_back(d+1, a-d, i+1); } vector<int> res = solve(move(data), z); if (res.empty()) { cout << "NIE\n"; } else { cout << "TAK\n"; bool first = true; for (auto const& x: res) { if (!first) cout << ' '; cout << x; first = false; } cout << '\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 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 | #include <algorithm> #include <iostream> #include <tuple> #include <vector> using namespace std; namespace { struct enemy { int limit; int delta; int id; enemy() = default; enemy(int limit_, int delta_, int id_): limit(limit_), delta(delta_), id(id_) {} }; vector<int> solve(vector<enemy> data, long long hp) { auto cmp = [](enemy const& a, enemy const& b) { if (a.delta >= 0 && b.delta < 0) return true; if (a.delta < 0 && b.delta >= 0) return false; if (a.delta >= 0) { return a.limit < b.limit; } else { return a.limit + a.delta > b.limit + b.delta; } }; sort(data.begin(), data.end(), cmp); vector<int> res; res.reserve(data.size()); for (auto const& e: data) { if (hp < e.limit) return {}; hp += e.delta; res.push_back(e.id); } return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(NULL); int n, z; cin >> n >> z; vector<enemy> data; data.reserve(n); for (int i = 0; i < n; ++i) { int d, a; cin >> d >> a; data.emplace_back(d+1, a-d, i+1); } vector<int> res = solve(move(data), z); if (res.empty()) { cout << "NIE\n"; } else { cout << "TAK\n"; bool first = true; for (auto const& x: res) { if (!first) cout << ' '; cout << x; first = false; } cout << '\n'; } return 0; } |