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;
const int mx=22;
int n,l,r,k;
typedef long long ll;
ll a[22];
int dp[mx][mx][10000];
int solve(int i,int j,int left){
int &ret=dp[i][j][left];
if(ret!=-1){return ret;}
if(i>=j){return 0;}
if(j>r){return 0;}
if(i>=l){return 0;}
if(j-i<=left){
ret=solve(i+1,j+1,left-(j-i))+(a[j]-a[i]);
}
ret=max(ret,solve(i+1,j,left));
ret=max(ret,solve(i,j+1,left));
ret=max(ret,solve(i+1,j+1,left));
return ret;
}
int main(){
cin>>n>>l>>r>>k;
l--;
r--;
ll sum=0;
ll ans;
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++){
cin>>a[i];
if(i>=l&&i<=r){sum+=a[i];}
}
ans=sum;
cout<<sum-solve(0,l,k);
}
Compilation message (stderr)
holding.cpp: In function 'int main()':
holding.cpp:29:4: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
29 | ll ans;
| ^~~
# | 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... |