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<stdio.h>
#define sq(a) ((a)*(a))
typedef long long lld;
int n, k, di[100100][202];
lld ba[100100], dy[100100][2], sum[100100];
int main(){
int i, i2, j, t=1;
scanf("%d%d", &n, &k);
for(i=1; i<=n; i++)scanf("%d", &ba[i]), sum[i]=sum[i-1]+ba[i];
for(i=1; i<=n; i++)dy[i][0]=sq(sum[i]);
for(j=1; j<=k; j++){
for(i=j+1, i2=j; i<=n; i++){
for(; i2<i-1; i2++){
if(sum[i2]>(lld)j*(sum[i]-sum[i2]))break;
}
di[i][j]=i2, dy[i][t]=dy[i2][1-t]+sq(sum[i]-sum[i2]);
if(i2>j){
if(dy[i][t]>dy[i2-1][1-t]+sq(sum[i]-sum[i2-1])){
di[i][j]=i2-1, dy[i][t]=dy[i2-1][1-t]+sq(sum[i]-sum[i2-1]);
}
}
}
t=1-t;
}
printf("%lld\n", (sq(sum[n])-dy[n][1-t])/2);
for(i=n, j=k; j>0; j--)printf("%d ", di[i][j]), i=di[i][j];
return 0;
}
# | 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... |