QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269189#5744. Palindromic Differencesucup-team1198#WA 1ms3372kbC++201.3kb2023-11-29 13:44:592023-11-29 13:45:00

Judging History

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

  • [2023-11-29 13:45:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3372kb
  • [2023-11-29 13:44:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()

#define int int64_t

const int MAXW = 1e4 + 100;
int dp[MAXW];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, w, k;
    cin >> n >> w >> k;
    vector<array<int, 2>> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i][0] >> arr[i][1];
    }
    sort(arr.begin(), arr.end());
    vector<int> pref(n + 1);
    for (int i = 0; i < n; ++i) {
        for (int j = w; j >= 0; --j) {
            if (j + arr[i][0] <= w) {
                dp[j + arr[i][0]] = max(dp[j + arr[i][0]], dp[j] + arr[i][1]);
            }
        }
        for (int j = 0; j <= w; ++j) {
            pref[i + 1] = max(pref[i + 1], dp[j]);
        }
    }

    vector<int> suf(n + 1);
    multiset<int> pr;
    int sum = 0;
    for (int i = n - 1; i >= 0; --i) {
        pr.insert(arr[i][1]);
        sum += arr[i][1];
        if ((int)pr.size() > k) {
            sum -= *pr.begin();
            pr.erase(pr.begin());
        }
        suf[i] = sum;
    }
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans = max(ans, pref[i] + suf[i]);
    }
    cout << ans << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3372kb

input:

5
3
2 3 1
4
1 1 1 1
3
1 2 4
7
0 200 0 200 50 100 150
14
-1 0 1 2 3 4 5 6 7 8 9 10 11 12

output:

8

result:

wrong answer 1st numbers differ - expected: '2', found: '8'