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