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