From f2d3f9b4755adaafe64df6cb9a91ada3c6ee6dd7 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 5 Oct 2022 14:06:04 +0800 Subject: [PATCH] P4025 [PA2014]Bohater https://www.luogu.com.cn/record/88686632 --- Luogu/P4025/P4025.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Luogu/P4025/P4025.cpp diff --git a/Luogu/P4025/P4025.cpp b/Luogu/P4025/P4025.cpp new file mode 100644 index 00000000..287de1e2 --- /dev/null +++ b/Luogu/P4025/P4025.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n; + long long k; + std::vector> up, down; + std::vector ans; + + cin >> n >> k; + + for (int i = 1, a, b; i <= n; i++) { + cin >> a >> b; + + if (b - a >= 0) up.emplace_back(i, a, b); + else down.emplace_back(i, a, b); + } + + std::sort(up.begin(), up.end(), [&](const auto &a, const auto &b) { + return std::get<1>(a) < std::get<1>(b); + }); + + std::sort(down.begin(), down.end(), [&](const auto &a, const auto &b) { + return std::get<2>(a) > std::get<2>(b); + }); + + for (auto o : up) { + k -= std::get<1>(o); + + if (k <= 0) { + cout << "NIE" << endl; + + exit(0); + } + + k += std::get<2>(o); + } + + for (auto o : down) { + k -= std::get<1>(o); + + if (k <= 0) { + cout << "NIE" << endl; + + exit(0); + } + + k += std::get<2>(o); + } + + cout << "TAK" << endl; + + for (auto o : up) { + cout << std::get<0>(o) << ' '; + } + + for (auto o : down) { + cout << std::get<0>(o) << ' '; + } + + cout << endl; + + return 0; +}