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>
#define ll long long
#define fr first
#define se second
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll a[101101], dp[111][111];
int main(){
///freopen("A.in", "r", stdin);
///freopen("A.out", "w", stdout);
ios;
ll n, m;
cin>>n>>m;
for(ll i = 1; i <= n; i ++){
cin>>a[i];
}
for(ll i = 1; i <= n; i ++){
dp[1][i]=max(dp[1][i-1],a[i]);
}
for(ll k = 2; k <= m; k ++){
for(ll i = k; i <= n; i ++){
ll mx = a[i];
dp[k][i]=dp[k-1][i-1]+mx;
for(ll j = i; j >= k; j --){
mx=max(mx,a[j]);
dp[k][i]=min(dp[k][i],dp[k-1][j-1]+mx);
}
///cout<<dp[k][i]<<' ';
}
}
///cout<<endl;
cout<<dp[m][n];
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... |