QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#456555 | #7132. Subset sums | Solove | WA | 0ms | 3624kb | C++23 | 1.3kb | 2024-06-28 06:45:15 | 2024-06-28 06:45:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n >> k;
ll sum = 0;
vector<int> a(n);
for (int i = 0; i < n; i++){
int x; cin >> x;
if (x < 0) {
sum += x;
a[i] = -a[i];
}
}
sort(a.begin(), a.end());
vector<ll> ans = {sum};
priority_queue<pair<ll, vector<int>>> q;
q.push({a[0], {0}});
for (int i = 0; i < k; i++){
auto nw = q.top();
ll val = nw.first;
auto v = nw.second;
q.pop();
ans.push_back(sum + val);
if (v.back() + 1 < n) {
auto nv = v;
nv.push_back(v.back() + 1);
q.push({val + a[nv.back()], nv});
int t = v.back();
val -= a[t];
v.pop_back();
t += 1;
val += a[t];
v.push_back(t);
q.push({val, v});
}
}
if (ans.back() <= 0) {
ans.pop_back();
} else {
ans.erase(find(ans.begin(), ans.end(), 0ll));
}
for (auto x : ans) {
cout << x << '\n';
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
2 3 -1 1
output:
-1 -1 -1
result:
wrong answer 2nd numbers differ - expected: '0', found: '-1'