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;
#define ll long long
const int ar = 1e5 + 5;
int n, k;
ll sum[ar], pos[205][ar], dp[205][ar];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; ++i) {
int x; cin >> x;
sum[i] = sum[i - 1] + x;
}
for(int i = 1; i <= k; ++i) {
for(int j = 1; j <= n; ++j) {
for(int h = 0; h < j; ++h) {
dp[i][j] = max(dp[i][j], dp[i - 1][h] + (sum[j] - sum[h]) * (sum[n] - sum[j]));
if(dp[i][j] == dp[i - 1][h] + (sum[j] - sum[h]) * (sum[n] - sum[j])) pos[i][j] = h;
}
}
}
ll mx = -1, ind = 0;
for(int i = k; i <= n; ++i) {
if(dp[k][i] > mx) mx = dp[k][i], ind = i;
}
cout << mx << '\n';
for(int i = k; i; --i) {
cout << ind << ' ';
ind = pos[i][ind];
}
}
# | 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... |