이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
bool calc [N][N][2];
long long dp [N][N][2];
long long arr [N];
int n, k;
long long solve (int p, int box, bool is) {
if (box < 0) return -1e15;
if (p >= n) return (box >= 0 ? 0 : -1e15);
if (calc[p][box][is]) return dp[p][box][is];
long long &res = dp[p][box][is];
calc[p][box][is] = true;
res = -1e15;
if (!is) {
res = max (res, solve (p + 1, box, false) );
res = max (res, solve (p + 1, box - 1, true) + arr[p]);
} else {
res = max (res, solve (p + 1, box, true) + arr[p]);
res = max (res, solve (p + 1, box, false) );
}
return res;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
memset (calc, false, sizeof(calc));
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> arr[i];
cout << solve (0, k, false) << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |