QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698950#7739. KnapsackSymmetreeWA 0ms4100kbC++171.3kb2024-11-01 23:17:532024-11-01 23:17:54

Judging History

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

  • [2024-11-01 23:17:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4100kb
  • [2024-11-01 23:17:53]
  • 提交

answer

#include<bits/stdc++.h>
const int N = 1e4+5;
using i64 = long long;
std::priority_queue<int, std::vector<int>, std::greater<int>> q;
int n, w, k; i64 ans, f[2][N], suf[N];
#define fi first 
#define se second
std::pair<int,int> o[N];
signed main() {
    //freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);
    scanf("%d%d%d", &n, &w, &k);
    for(int i = 1; i <= n; ++i) scanf("%d%d", &o[i].fi, &o[i].se);
    std::sort(o + 1, o + n + 1);
    memset(f, 0xcf, sizeof f);
    f[0][0] = 0;
    if(n <= k) {
        for(int i = 1; i <= n; ++i) ans += o[i].se;
        printf("%lld\n", ans);
        return 0;
    }
    i64 num = 0;
    for(int i = n; i > n - k; --i) suf[i] = num, q.push(o[i].se), num += o[i].se;
    for(int i = n - k; i; --i) {
        suf[i] = num;
        num += o[i].se, q.push(o[i].se);
        num -= q.top(), q.pop();
    }
    ans = suf[0] = num;
    for(int i = 1; i <= n; ++i) {
        i64 ss = 0;
        //for(int j = 0; j <= w; ++j) f[i & 1][j] = 0;
        //for(int j = 0; j < o[i].fi; ++j) f[i & 1][j] = f[(i - 1) & 1][j];
        for(int j = o[i].fi; j <= w; ++j) {
            f[i & 1][j] = std::max(f[(i - 1) & 1][j], f[(i - 1) & 1][j - o[i].fi] + o[i].se);
        }
        for(int j = 0; j <= w; ++j) ss = std::max(ss, f[i & 1][j]);
        ans = std::max(ans, ss + suf[i]);
    }
    printf("%lld\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4096kb

input:

4 10 1
9 10
10 1
3 5
5 20

output:

35

result:

ok 1 number(s): "35"

Test #2:

score: 0
Accepted
time: 0ms
memory: 4012kb

input:

5 13 2
5 16
5 28
7 44
8 15
8 41

output:

129

result:

ok 1 number(s): "129"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 4100kb

input:

10 50 1
44 182173741
38 163268500
36 114173760
30 521894533
25 89514235
12 516184197
42 971377551
35 28242326
31 480227821
31 388523197

output:

1876084945

result:

wrong answer 1st numbers differ - expected: '2009456281', found: '1876084945'