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 int long long
#define task "block"
using namespace std;
using ii=pair<int,int>;
const int mn=1e5+11;
const int mk=111;
int n,k;
int a[mn];
int dp[mn][mk];
ii st[mn];
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
memset(dp,0x3f,sizeof(dp));
dp[0][0]=0;
for(int j=1;j<=k;j++){
int cnt=0;
for(int i=j;i<=n;i++){
int mval=dp[i-1][j-1];
while(cnt && a[st[cnt].first]<=a[i]){
mval=min(mval,st[cnt].second);
cnt--;
}
dp[i][j]=min(dp[st[cnt].first][j],mval+a[i]);
st[++cnt]=ii(j,mval);
}
}
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... |