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;
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<ll> pref(n + 1, 0);
partial_sum(a.begin(), a.end(), pref.begin() + 1);
ll dp[k + 1][n], parent[k + 1][n];
memset(dp, 0xff, sizeof(dp));
memset(parent, 0xff, sizeof(dp));
for (int j = 0; j < n; ++j) {
dp[0][j] = 0;
}
for (int i = 1; i <= k; ++i) {
for (int j = 0; j < n; ++j) {
for (int h = i - 1; h < j; ++h) {
ll t = dp[i - 1][h] +
(pref[h + 1] - pref[0]) * (pref[j + 1] - pref[h + 1]);
if (t >= dp[i][j]) {
dp[i][j] = t;
parent[i][j] = h;
}
}
}
}
cout << dp[k][n - 1] << endl;
int u = n - 1;
for (int i = k; i > 0; --i) {
u = parent[i][u];
cout << (u + 1) << ' ';
}
cout << 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... |