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;
int dp[101][101], a[101],n,k;
int main(){
int i,j,t;
cin>>n>>k;
for(i=1;i<=n; i++)
cin>>a[i];
for(i=1;i<=n; i++)
dp[1][i] = max(a[i], dp[1][i-1]);
for(i=2;i<=k;i++){
for(j=i;j<=n;j++){
int mx=a[j];
dp[i][j]=dp[i-1][j-1] + a[j];
for(t=j;t>=i; t--){
mx=max(mx,a[t]);
dp[i][j]=min(dp[i][j], dp[i-1][t-1] + mx);
}
}
}
cout<<dp[k][n]<<endl;
}
# | 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... |