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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define forinc(x,a,b) for(int x=a;x<=b;x++)
#define fordec(x,a,b) for(int x=a;x>=b;x--)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1ll<<i))
#define endl '\n'
const int N=2501;
int n,l,r,k;
ii a[101];
ii b[101];
main()
{
fasty;
//freopen("task.inp","r",stdin);
cin>>n>>l>>r>>k;
k=min(k,(n*n)/4);
int cnt1=0;
int cnt2=0;
forinc(i,1,n)
{
int x;cin>>x;
if(i>=l&&i<=r) b[++cnt2]={x,i};
else a[++cnt1]={x,i};
}
int f[cnt1+3][cnt2+3][N];
memset(f,127,sizeof f);
int inf=f[0][0][0];
int res=inf;
f[1][1][0]=0;
forinc(i,1,cnt1+1) forinc(j,1,cnt2+1) forinc(ti,0,k) if(f[i][j][ti]<inf)
{
int ticost=abs(b[j].se-a[i].se);
if(ti+ticost<=k) f[i+1][j+1][ti+ticost]=min(f[i+1][j+1][ti+ticost],f[i][j][ti]+a[i].fi);
if(i+1<=cnt1+1) f[i+1][j][ti]=min(f[i+1][j][ti],f[i][j][ti]);
if(j+1<=cnt2+1) f[i][j+1][ti]=min(f[i+1][j+1][ti],f[i][j][ti]+b[j].fi);
}
forinc(i,1,cnt1+1) forinc(ti,0,k)
{
res=min(res,f[i][cnt2+1][ti]);
}
cout<<res;
}
Compilation message (stderr)
holding.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
22 | 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... |