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 int long long
#define se second
#define fi first
#define pb push_back
int n,k;
int a[100005];
int dp[100005][104];
signed main(){
cin>>n>>k;
for (int i=1;i<=n;i++){
cin>>a[i];
}
for (int i=1;i<=k;i++){
for (int j=1;j<=n;j++){
dp[i][j]=INT_MAX;
}
}
for (int i=1;i<=n;i++){
int maxx=0;
maxx=max(maxx,a[i]);
dp[1][i]=maxx;
}
for (int i=1;i<=k;i++){
for (int j=i;j<=n;j++){
int maxx=0;
for (int l=j;l>=i;l--){
maxx=max(maxx,a[l]);
dp[i][j]=min(dp[i][j],dp[i-1][l-1]+maxx);
}
}
}
cout<<dp[k][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... |