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;
#define endl "\n"
typedef long long int ll;
const int N=1e5+7;
const int K=102;
int a[N];
int n;
ll dp[N][K];
int v;
int query(int l,int r){
int ans=0;
for(int i=l; i<=r; i++) {
ans=max(ans,a[i]);
}
return ans;
}
int solve(int idx,int k){
if(idx==n+1) {
if(k==v+1) {
return 0;
}
return 1e9;
}
if(dp[idx][k]!=-1) {
return dp[idx][k];
}
int ans=1e9;
for(int j=idx; j<=n; j++) {
ans=min(ans,query(idx,j)+solve(j+1,k+1));
}
return dp[idx][k]=ans;
}
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
cin>>n>>v;
for(int i=1; i<=n; i++) cin>>a[i];
memset(dp,-1,sizeof dp);
ll ans=solve(1,1);
cout<<ans<<endl;
return 0;
}
# | 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... |