From 401024ab868cc161f82bf05ecb380dc9c368741c Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 21 Jul 2025 11:54:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=BB=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=EF=BC=8C=E5=8C=85=E5=90=AB=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E5=A4=84=E7=90=86=E3=80=81=E8=B4=9F=E6=95=B0=E6=B1=82=E5=92=8C?= =?UTF-8?q?=E3=80=81=E7=BB=9D=E5=AF=B9=E5=80=BC=E6=8E=92=E5=BA=8F=E5=8F=8A?= =?UTF-8?q?=E4=BC=98=E5=85=88=E9=98=9F=E5=88=97=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/7/21/T636328d.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/7/21/T636328d.cpp diff --git a/src/7/21/T636328d.cpp b/src/7/21/T636328d.cpp new file mode 100644 index 0000000..540c8e9 --- /dev/null +++ b/src/7/21/T636328d.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; +using ll = long long; + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + ll n, k; + cin >> n >> k; + vector a(n); + ll C = 0; + for (ll i = 0; i < n; i++) { + cin >> a[i]; + if (a[i] < 0) { + C += a[i]; + } + } + + vector b; + for (ll x : a) { + b.push_back(abs(x)); + } + sort(b.begin(), b.end()); + + priority_queue, vector>, greater<>> pq; + pq.push({0, 0}); + + vector ans; + while (ans.size() < k && !pq.empty()) { + auto [sum, idx] = pq.top(); + pq.pop(); + if (idx == n) { + ans.push_back(sum + C); + } else { + pq.push({sum, idx + 1}); + pq.push({sum + b[idx], idx + 1}); + } + } + + for (ll i = 0; i < ans.size(); i++) { + cout << ans[i]; + if (i < ans.size() - 1) { + cout << ' '; + } + } + cout << endl; + + return 0; +} \ No newline at end of file