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>
int arr[1111111];
int dp[211][111111];
int bt[211][111111];
int sum[1111111];
int seq[111111];
int n,K;
int main()
{
scanf("%d%d",&n,&K);
int i,j,k;
for(i=1;i<=n;i++) {
scanf("%d",&sum[i]);
sum[i] += sum[i-1];
}
dp[1][1]=sum[1] * (sum[n]-sum[1]);
int ans=-1,kk=n;
for(k=1;k<=K;k++){
for(i=1;i<=n;i++){
for(j=0;j<i;j++) {
if(dp[k-1][j] + (sum[i]-sum[j])*(sum[n]-sum[i]) > dp[k][i]){
dp[k][i] = dp[k-1][j] + (sum[i]-sum[j])*(sum[n]-sum[i]);
bt[k][i] = j;
if(k==K && dp[k][i] >ans){
ans = dp[k][i];
kk=i;
}
}
}
}
}
printf("%d\n",ans);
int a=kk;
seq[K+1]=kk;
for(k=K;k>=1;k--){
seq[k]=bt[k][a];
a = bt[k][a];
}
for(i=2;i<=K+1;i++) printf("%d ",seq[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... |