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 iii pair<ii,int>
#define fi first
#define se second
#define ii pair<int,int>
#define getbit(x,i) ((x>>(i))&1ll)
#define batbit(x,i) (x|(1ll<<(i)))
#define tatbit(x,i) (x&~(1ll<<(i)))
#define endl '\n'
//#define int long long
#define pb push_back
#define ll long long
const int N = 103;
const int K = 1e4+3;
int n,L,R,k;
int a[N];
int f[N][N][2510];
main()
{
fasty;
cin >> n >> L >> R >> k;
vector<ii> c;
vector<ii> d;
k=min(k , n*n / 4);
int sum=0;
forinc(i,1,n)
{
cin >> a[i];
if(i<L || i > R) c.pb({a[i] , i});
else
{
d.pb({a[i] ,i});
sum+=a[i];
}
}
forinc(i,0,n) forinc(j,0,n) forinc(t,0,k) f[i][j][t]=sum;
int n1 = c.size();
int n2 = d.size();
int res=sum;
forinc(i,1,n1) forinc(j,1,n2) forinc(t,0,k)
{
int cost = abs(c[i-1].se - d[j-1].se);
f[i][j][t] = min(f[i-1][j][t] , f[i][j-1][t]);
if(t) f[i][j][t] = min(f[i][j][t] , f[i][j][t-1]);
if(t>=cost)
{
f[i][j][t] = min(f[i-1][j-1][t-cost] - d[j-1].fi + c[i-1].fi , f[i][j][t]);
}
}
forinc(i,1,n1) forinc(j,1,n2) forinc(t,0,k)
{
res = min(res , f[i][j][t]);
}
cout << res;
}
Compilation message (stderr)
holding.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | 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... |