# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552511 | tht2005 | Split the sequence (APIO14_sequence) | C++17 | 63 ms | 131072 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;
typedef long long LL;
const LL INF = numeric_limits<LL>::max() / 2;
const int N = 100001;
const int K = 201;
int n, kk;
LL s[N], f[K][N];
int main() {
scanf("%d %d", &n, &kk);
for(int i = 1; i <= n; ++i) {
int a;
scanf("%d", &a);
s[i] = s[i - 1] + a;
}
memset(f, 0, sizeof(f));
for(int t = 1; t <= kk; ++t) {
for(int i = t + 1; i <= n; ++i) {
for(int j = i - 1; j >= t; --j) {
f[t][i] = max(f[t][i], f[t - 1][j] + s[j] * (s[i] - s[j]));
}
}
}
printf("%lld\n", f[kk][n]);
for(int i, j = n; kk--; ) {
for(i = j; i--; ) {
if(f[kk + 1][j] == f[kk][i] + s[i] * (s[j] - s[i])) {
printf("%d ", i);
j = i;
break;
}
}
}
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... |