This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |