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 endl "\n"
#define all(aa) aa.begin(), aa.end()
int main(){
int n, L, R, C;
cin>>n>>L>>R>>C;
vector<int> val(n+1);
int ans=0;
for(int i=1; i<=n; i++){
cin>>val[i];
if(i>=L && i<=R) ans+=val[i];
}
vector<vector<vector<int>>> dp_l(L+2, vector<vector<int>>(n+2, vector<int>(C+1)));
for(int i=R; i>=L; i--){
vector<vector<vector<int>>> dp(L+2, vector<vector<int>>(n+2, vector<int>(C+1)));
for(int l=1; l<=L-1; l++){
for(int r=n; r>=R+1; r--){
for(int c=0; c<=C; c++){
dp[l][r][c]=min(0, dp_l[l][r][c]);
if(l>0){
if(c>=i-l)
dp[l][r][c]=min(dp[l][r][c], dp_l[l-1][r][c-(i-l)]+val[l]-val[i]);
dp[l][r][c]=min(dp[l][r][c], dp[l-1][r][c]);
}
if(r<=n){
if(c>=r-i)
dp[l][r][c]=min(dp[l][r][c], dp_l[l][r+1][c-(r-i)]+val[r]-val[i]);
dp[l][r][c]=min(dp[l][r][c], dp[l][r+1][c]);
}
}
}
}
dp_l=dp;
}
cout<<ans+dp_l[L-1][R+1][C];
}
# | 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... |