QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#456555#7132. Subset sumsSoloveWA 0ms3624kbC++231.3kb2024-06-28 06:45:152024-06-28 06:45:15

Judging History

你现在查看的是最新测评结果

  • [2024-06-28 06:45:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-06-28 06:45:15]
  • 提交

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'