QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269189 | #5744. Palindromic Differences | ucup-team1198# | WA | 1ms | 3372kb | C++20 | 1.3kb | 2023-11-29 13:44:59 | 2023-11-29 13:45:00 |
Judging History
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;
}
詳細信息
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'