#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
const int MAXN = 100 + 5;
const int MAXK = 10000 + 5;
const int INF = 1e9;
#ifndef ONLINE_JUDGE
#define OPEN freopen(".in", "r", stdin); \
freopen(".out", "w", stdout);
#else
#define OPEN void(23);
#endif
int dp[MAXN][MAXN][MAXK / 4];
void solve()
{
memset(dp, -1, sizeof(dp));
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];
k = min(k, MAXK / 4);
function <int(int, int, int)> f = [&](int x, int ind, int nw) -> int
{
if(ind > r +1) return INF;
if(nw > k) return INF;
if(x == n +1) return (ind == r +1 ? 0 : INF);
int &it = dp[x][ind][nw];
if(it != -1) return it;
//cerr << x << " " << ind << " " << nw << "\n";
int res = f(x +1, ind +1, nw + abs(ind - x)) + vec[x];
res = min(res, f(x +1, ind, nw));
return it = res;
};
cout << f(1, l, 0);
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();
}
}
Compilation message
holding.cpp: In function 'int32_t main()':
holding.cpp:12:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define OPEN freopen(".in", "r", stdin); \
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
holding.cpp:51:5: note: in expansion of macro 'OPEN'
51 | OPEN;
| ^~~~
holding.cpp:13:25: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
holding.cpp:51:5: note: in expansion of macro 'OPEN'
51 | OPEN;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
108440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
108440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
108440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
108440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |