# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222912 | Bruteforceman | Split the sequence (APIO14_sequence) | C++11 | 2081 ms | 5752 KiB |
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;
int a[100010];
int n, k;
long long pre[100010];
long long dp[202][100010], opt[202][100010];
const long long inf = 1e17;
int main() {
scanf("%d %d", &n, &k);
k += 1;
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
for(int i = 1; i <= n; i++) {
pre[i] = pre[i - 1] + a[i];
}
long long sum = pre[n];
for(int j = 1; j <= n; j++) {
dp[0][j] = -inf;
}
dp[0][0] = 0;
for(int i = 1; i <= k; i++) {
for(int j = 0; j <= n; j++) {
dp[i][j] = -inf;
for(int x = 0; x < j; x++) {
long long cost = dp[i - 1][x] +
(sum - pre[j] + pre[x]) * (pre[j] - pre[x]);
if(cost > dp[i][j]) {
dp[i][j] = cost;
opt[i][j] = x;
}
}
}
}
printf("%lld\n", dp[k][n] / 2);
int cur = n;
int cnt = k;
while(cnt) {
cur = opt[cnt--][cur];
if(cur) printf("%d ", cur);
}
puts("");
return 0;
}
Compilation message (stderr)
# | 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... |