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+2][k+2]; A[0] = 0;
for(int i = 1; i <= n; i++) cin >> A[i];
for(int i = 0; i < n+2; i++) DP[i][0] = 0;
for(int i = 0; i < k+2; i++) DP[0][i] = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= k; j++) {
DP[i][j] = DP[i-1][j];
ll ns = A[i];
for(int l = i-1; l >= 0; l--) {
DP[i][j] = max(DP[i][j], DP[l][j-1]+ns);
ns += A[l];
}
}
}
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... |