#include <iostream> #include <algorithm> #include <utility> #include <vector> #include <tuple> int main() { std::cin.sync_with_stdio(false); int n; long long z; std::cin >> n >> z; long long d, a; std::vector<std::tuple<long long, long long, int> > poz; std::vector<std::tuple<long long, long long, int> > neg; for (int i = 0; i < n; ++i) { std::cin >> d >> a; if (a-d >= 0) { std::tuple<long long, long long, int> dane = std::make_tuple(d, a-d, i+1); poz.push_back(dane); } else { // std::tuple<long long, long long, int> dane = std::make_tuple(d, a-d, i+1); std::tuple<long long, long long, int> dane = std::make_tuple(a, d, i+1); neg.push_back(dane); } } std::sort(poz.begin(), poz.end()); std::sort(neg.begin(), neg.end()); for (int i = 0; i < poz.size(); ++i) { long long dmg = std::get<0>(poz[i]); long long delta = std::get<1>(poz[i]); if (z <= dmg) { std::cout << "NIE\n"; return 0; } else { z += delta; } } /* for (int i = neg.size() - 1; i >= 0; --i) { long long dmg = std::get<0>(neg[i]); long long delta = std::get<1>(neg[i]); if (z <= dmg) { std::cout << "NIE\n"; return 0; } else { z += delta; } } */ for (int i = neg.size() - 1; i >= 0; --i) { long long dmg = std::get<1>(neg[i]); long long hp = std::get<0>(neg[i]); long long delta = hp - dmg; if (z <= dmg) { std::cout << "NIE\n"; return 0; } else { z += delta; } } if (z > 0) { std::cout << "TAK\n"; for (int i = 0; i < poz.size(); ++i) { std::cout << std::get<2>(poz[i]) << " "; } /* for (int i = neg.size() - 1; i >= 0; --i) { std::cout << std::get<2>(neg[i]) << " "; } */ for (int i = neg.size() - 1; i >= 0; --i) { std::cout << std::get<2>(neg[i]) << " "; } } 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 | #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <tuple> int main() { std::cin.sync_with_stdio(false); int n; long long z; std::cin >> n >> z; long long d, a; std::vector<std::tuple<long long, long long, int> > poz; std::vector<std::tuple<long long, long long, int> > neg; for (int i = 0; i < n; ++i) { std::cin >> d >> a; if (a-d >= 0) { std::tuple<long long, long long, int> dane = std::make_tuple(d, a-d, i+1); poz.push_back(dane); } else { // std::tuple<long long, long long, int> dane = std::make_tuple(d, a-d, i+1); std::tuple<long long, long long, int> dane = std::make_tuple(a, d, i+1); neg.push_back(dane); } } std::sort(poz.begin(), poz.end()); std::sort(neg.begin(), neg.end()); for (int i = 0; i < poz.size(); ++i) { long long dmg = std::get<0>(poz[i]); long long delta = std::get<1>(poz[i]); if (z <= dmg) { std::cout << "NIE\n"; return 0; } else { z += delta; } } /* for (int i = neg.size() - 1; i >= 0; --i) { long long dmg = std::get<0>(neg[i]); long long delta = std::get<1>(neg[i]); if (z <= dmg) { std::cout << "NIE\n"; return 0; } else { z += delta; } } */ for (int i = neg.size() - 1; i >= 0; --i) { long long dmg = std::get<1>(neg[i]); long long hp = std::get<0>(neg[i]); long long delta = hp - dmg; if (z <= dmg) { std::cout << "NIE\n"; return 0; } else { z += delta; } } if (z > 0) { std::cout << "TAK\n"; for (int i = 0; i < poz.size(); ++i) { std::cout << std::get<2>(poz[i]) << " "; } /* for (int i = neg.size() - 1; i >= 0; --i) { std::cout << std::get<2>(neg[i]) << " "; } */ for (int i = neg.size() - 1; i >= 0; --i) { std::cout << std::get<2>(neg[i]) << " "; } } return 0; } |