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 <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int main() {
//not uy tins
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
vector<vector<int>> dp(K + 1, vector<int>(N + 1, 0));
vector<int> prefixSum(N + 1, 0);
for (int i = 1; i <= N; ++i) {
prefixSum[i] = prefixSum[i - 1] + A[i - 1];
}
for (int k = 1; k <= K; ++k) {
for (int n = 1; n <= N; ++n) {
dp[k][n] = dp[k][n - 1];
for (int i = 0; i < n; ++i) {
dp[k][n] = max(dp[k][n], dp[k - 1][i] + prefixSum[n] - prefixSum[i]);
}
}
}
cout << dp[K][N] << endl;
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... |