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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ft first
#define sc second
using namespace std;
const int mod=1e9+7,INF=1e17;
int n,k,dp[105][105],mx=-INF,a[105];
main(){
cin >> n >> k;
for(int i=1;i<=n;i++){
cin >> a[i];
}
for(int i=1;i<=n;i++){
mx=max(mx,a[i]);
dp[1][i]=mx;
}
for(int i=2;i<=k;i++){
for(int j=i+1;j<=n;j++){
int ans=INF,h=a[j];
for(int l=j-1;l>=i-1;l--){
if(dp[i-1][l]+h<ans){
ans=dp[i-1][l]+h;
}
h=max(h,a[l]);
}
dp[i][j]=ans;
}
}
cout << dp[k][n];
}
Compilation message (stderr)
blocks.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main(){
| ^~~~
# | 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... |