This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O2,unroll-loops,inline")
#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define pb push_back
#define prec fixed<<setprecision
#define endl '\n'
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define open(name) if(fopen(name".inp", "r")){freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
using namespace std;
const int maxN=103;
const int mod=998244353;
ll n,l,r,z,a[maxN],f[102][2503],old[102][2503],g[102][2503];
void Enter(){
cin>>n>>l>>r>>z;
z=min(z,n*n/4);
ll res=0;
for(int i=1;i<=n;i++){
cin>>a[i];
if(l<=i&&i<=r)res+=a[i];
}
//f[i][j][k]=so tien giam bot lon nhat khi thay [L,j] bang cac ptu trong [1,i] voi chi phi k, swap(a[i],a[j])
// tuong tu voi g
for(int i=1;i<l;i++){
memset(f,0,sizeof f);
for(int j=r;j>=l;j--)for(int k=z;k;k--){
f[j][k]=max(f[j-1][k],old[j][k]);
if(k>=j-i)f[j][k]=max(f[j][k],old[j-1][k-j+i]+a[j]-a[i]);
}
swap(old,f);
}
swap(old,f);
memset(old,0,sizeof old);
for(int i=n;i>r;i--){
memset(g,0,sizeof g);
for(int j=r;j>=l;j--)for(int k=0;k<=z;k++){
g[j][k]=max(g[j+1][k],old[j][k]);
if(k>=i-j)g[j][k]=max(g[j][k],old[j+1][k+j-i]+a[j]-a[i]);
}
swap(old,g);
}
swap(old,g);
ll x=max(f[r][z],g[l][z]);
for(int i=l;i<=r;i++)for(int k=0;k<=z;k++)x=max(x,f[i][k]+g[i+1][z-k]);
cout<<res-x;
}
//amogus
signed main(){
open("DEBT");
cin.tie(nullptr);ios_base::sync_with_stdio(NULL);
//ll t=1;cin>>t;while(t--)
Enter();
}
Compilation message (stderr)
holding.cpp: In function 'int main()':
holding.cpp:11:54: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | #define open(name) if(fopen(name".inp", "r")){freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:51:5: note: in expansion of macro 'open'
51 | open("DEBT");
| ^~~~
holding.cpp:11:87: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | #define open(name) if(fopen(name".inp", "r")){freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:51:5: note: in expansion of macro 'open'
51 | open("DEBT");
| ^~~~
# | 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... |