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("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define OPEN freopen(".in", "r", stdin); \
freopen(".out", "w", stdout);
#else
#define OPEN void(23);
#endif
void solve()
{
int n, l, r, k; cin >> n >> l >> r >> k;
vector <int> vec(n +1);
for(int i = 1; i <= n; i++) cin >> vec[i];
int ans = 1e9;
function <void(int, int)> dfs = [&](int x, int nw) -> void
{
if(nw > k) return;
//cerr << x << " " << nw << "\n";
if(x == n +1)
{
int calc = 0;
for(int i = l; i <= r; i++) calc += vec[i];
ans = min(ans, calc);
return;
}
for(int i = x; i >= 1; i--)
{
swap(vec[i], vec[x]);
dfs(x +1, nw + (x - i));
swap(vec[i], vec[x]);
}
};
dfs(1, 0);
cout << ans << "\n";
return;
}
int32_t main()
{
OPEN;
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1; //cin >> t;
while(t--)
{
solve();
}
}
# | 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... |