Submission #7632

#TimeUsernameProblemLanguageResultExecution timeMemory
7632myungwooSplit the sequence (APIO14_sequence)C++98
0 / 100
0 ms2680 KiB
#include <stdio.h> #define MAXN 1004 #define MAXK 202 int N,K,A[MAXN],S[MAXN],D[MAXN][MAXK],P[MAXN][MAXK]; int main() { int i,j,k; scanf("%d%d",&N,&K); ++K; for (i=1;i<=N;i++) scanf("%d",A+i), S[i] = S[i-1]+A[i]; for (i=1;i<=N;i++) for (j=0;j<=K;j++) D[i][j] = -1e9; D[0][0] = 0; for (j=1;j<=K;j++){ for (i=1;i<=N;i++){ for (k=0;k<i;k++) if (D[k][j-1] >= 0){ if (D[i][j] < D[k][j-1]+(S[i]-S[k])*S[k]) D[i][j] = D[k][j-1]+(S[i]-S[k])*S[k], P[i][j] = k; } } } printf("%d\n",D[N][K]); for (i=N,j=K;j;){ if (i < N) printf("%d ",i); i = P[i][j]; j--; } puts(""); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...