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 int lld;
#define MAX 101010
lld arr[MAX], dp[MAX], p[MAX], s[MAX], ans[MAX];
int path[MAX][202];
void f(lld ind, lld l, lld r, lld low, lld high){
if(l>r||low>high) return;
lld i, mid=(l+r)/2, mini=mid-1;
dp[mid]=0;
for(i=max(low, ind-1);i<=min(high, mid-1);i++){
if(dp[mid]<p[i]+s[i]*(s[mid]-s[i])){
dp[mid]=p[i]+s[i]*(s[mid]-s[i]);
mini=i;
}
}
path[mid][ind]=(int)mini;
f(ind, l, mid-1, low, mini);
f(ind, mid+1, r, mini, high);
}
int main(void){
lld N, K;
scanf("%lld %lld", &N, &K);
lld i;
for(i=1;i<=N;i++){
scanf("%lld", &arr[i]);
s[i]=arr[i]+s[i-1];
}
int j;
for(i=2;i<=K+1;i++){
f(i, 1, N, 1, N);
for(j=1;j<=N;j++){
p[j]=dp[j];
}
}
printf("%lld\n", dp[N]);
for(i=K+1;i>=2;i--){
ans[i]=(lld)path[N][i];
N=(lld)path[N][i];
}
for(i=2;i<=K+1;i++){
printf("%lld ", ans[i]);
}
printf("\n");
return 0;
}
Compilation message (stderr)
sequence.cpp: In function 'int main()':
sequence.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
23 | scanf("%lld %lld", &N, &K);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
26 | scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
# | 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... |