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;
typedef long long ll;
int main() {
int n, k; cin >> n >> k;
ll A[n+1], DP[n+1][k+1], PS[n+1], B[k+1];
A[0] = PS[0] = 0;
for(int i = 1; i <= n; i++) cin >> A[i], PS[i] = PS[i-1]+A[i];
for(int i = 0; i < k+1; i++) B[i] = PS[n];
for(int i = 0; i < n+1; i++) DP[i][0] = 0;
for(int i = 0; i < k+1; i++) DP[0][i] = 0;
for(int i = 1; i <= n; i++) {
B[0] = max(B[0], PS[n]-PS[i]);
for(int j = 1; j <= k; j++) {
DP[i][j] = max(DP[i-1][j], B[j-1]-(PS[n]-PS[i]));
B[j] = max(B[j], DP[i][j]+(PS[n]-PS[i]));
}
}
cout << DP[n][k];
}
# | 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... |