# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552530 | tht2005 | Split the sequence (APIO14_sequence) | C++17 | 2098 ms | 3528 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 int N = 100005;
const int K = 202;
int n, kk, s[N], trc[K][N];
LL f[N], g[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) {
memcpy(g, f, sizeof(g));
memset(f, 0, sizeof(f));
for(int i = t + 1; i <= n; ++i) {
trc[t][i] = i - 1;
for(int j = i - 1; j >= t; --j) {
LL _ = g[j] + (LL)s[j] * (s[i] - s[j]);
if(f[i] < _) {
f[i] = _;
trc[t][i] = j;
}
}
}
}
printf("%lld\n", f[n]);
for(int i = n; (i = trc[kk--][i]); ) {
printf("%d ", i);
}
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... |