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 ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,k;
cin>>n>>k;
ll a[n+5];
for(ll i=1;i<=n;i++){
cin>>a[i];
}
ll dp[n+5][k+5];
for(ll i=0;i<=n;i++){
for(ll j=0;j<=k;j++){
dp[i][j]=1e18;
}
}
dp[0][0]=0;
for(ll r=1;r<=n;r++){
ll mx=0;
for(ll l=r;l>=1;l--){
mx=max(mx,a[l]);
for(ll i=1;i<=k;i++){
dp[r][i]=min(dp[r][i],dp[l-1][i-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... |