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 = 2007;
int n, K, a[N];
long long f[N][N][2], ans = 0;
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cin >> n >> K;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= K; j++) {
f[i][j][0] = max(f[i - 1][j][0], f[i - 1][j][1]);
if(j > 0) f[i][j][1] = max(f[i - 1][j - 1][0], f[i - 1][j][1]) + a[i];
}
}
for(int i = 0; i <= K; i++) ans = max(ans, max(f[n][i][0], f[n][i][1]));
cout << ans;
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... |