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 MAXN 1004
#define MAXK 202
typedef long long lld;
int N,K,A[MAXN],S[MAXN],P[MAXN][MAXK];
lld D[MAXN][MAXK];
int main()
{
int i,j,k;
scanf("%d%d",&N,&K);
for (i=1;i<=N;i++) scanf("%d",A+i), S[i] = S[i-1]+A[i];
for (j=1;j<=K;j++){
for (i=1;i<=N;i++){
for (k=j;k<i;k++){
if (D[i][j] < D[k][j-1]+(lld)(S[i]-S[k])*S[k])
D[i][j] = D[k][j-1]+(lld)(S[i]-S[k])*S[k], P[i][j] = k;
}
}
}
printf("%lld\n",D[N][K]);
for (i=N,j=K;i;){
if (i < N) printf("%d ",i);
i = P[i][j]; j--;
} puts("");
}
# | 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... |