# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29705 | sampriti | Split the sequence (APIO14_sequence) | C++14 | 2000 ms | 25964 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 <cstdio>
#include <algorithm>
#include <climits>
using namespace std;
int N, K;
int A[100001];
long long P[100001];
long long dp[10002][202];
int nxt[10002][202];
int main() {
scanf("%d %d", &N, &K);
for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
for(int i = 1; i <= N; i++) P[i] = P[i - 1] + A[i];
dp[N + 1][1] = LLONG_MIN/2;
for(int j = 2; j <= K + 1; j++) {
dp[N + 1][j] = LLONG_MIN/2;
for(int i = N; i >= 1; i--) {
dp[i][j] = LLONG_MIN/2;
for(int k = i; k <= N; k++) {
long long curr = (P[k] - P[i - 1]) * (P[N] - P[k]) + dp[k + 1][j - 1];
if(curr > dp[i][j]) {
dp[i][j] = curr;
nxt[i][j] = k;
}
}
}
}
printf("%lld\n", dp[1][K + 1]);
int i = 1, j = K + 1;
while(j > 1) {
printf("%d ", nxt[i][j]);
i = nxt[i][j] + 1;
j--;
}
printf("\n");
}
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... |