#include <bits/stdc++.h>
using namespace std;
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; }
const int MAXN = 101;
int N, L, R, A[MAXN], K, dp[2][MAXN][MAXN * MAXN];
void you_make_it(void) {
cin >> N >> L >> R >> K;
int length = R - L + 1;
FOR(i, 1, N) cin >> A[i];
memset(dp, 0x3f, sizeof dp);
dp[0][0][0] = 0;
FOR(i, 1, N) {
memset(dp[i & 1], 0x3f, sizeof dp[i & 1]);
FOR(j, 0, length) {
FOR(k, 0, K) {
dp[i & 1][j][k] = dp[(i - 1) & 1][j][k];
if(j > 0) {
int cost = abs(i - (L + j - 1));
if(k - cost >= 0) {
minimize(dp[i & 1][j][k], dp[(i - 1) & 1][j - 1][k - cost] + A[i]);
}
}
}
}
}
cout << *min_element(dp[N & 1][length], dp[N & 1][length] + K + 1);
}
signed main() {
#ifdef LOCAL
freopen("TASK.inp", "r", stdin);
freopen("TASK.out", "w", stdout);
#endif
auto start_time = chrono::steady_clock::now();
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
you_make_it();
auto end_time = chrono::steady_clock::now();
cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
// Dream it. Wish it. Do it.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
3 ms |
8280 KB |
Output is correct |
3 |
Correct |
3 ms |
8280 KB |
Output is correct |
4 |
Correct |
3 ms |
8280 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8280 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
3 ms |
8280 KB |
Output is correct |
3 |
Correct |
3 ms |
8280 KB |
Output is correct |
4 |
Correct |
3 ms |
8280 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8280 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
5 ms |
8280 KB |
Output is correct |
9 |
Correct |
5 ms |
8280 KB |
Output is correct |
10 |
Correct |
5 ms |
8284 KB |
Output is correct |
11 |
Correct |
5 ms |
8284 KB |
Output is correct |
12 |
Correct |
5 ms |
8280 KB |
Output is correct |
13 |
Correct |
26 ms |
8512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
3 ms |
8280 KB |
Output is correct |
3 |
Correct |
3 ms |
8280 KB |
Output is correct |
4 |
Correct |
3 ms |
8280 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8280 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
5 ms |
8280 KB |
Output is correct |
9 |
Correct |
5 ms |
8280 KB |
Output is correct |
10 |
Correct |
5 ms |
8284 KB |
Output is correct |
11 |
Correct |
5 ms |
8284 KB |
Output is correct |
12 |
Correct |
5 ms |
8280 KB |
Output is correct |
13 |
Correct |
26 ms |
8512 KB |
Output is correct |
14 |
Correct |
5 ms |
8284 KB |
Output is correct |
15 |
Correct |
5 ms |
8432 KB |
Output is correct |
16 |
Correct |
5 ms |
8280 KB |
Output is correct |
17 |
Correct |
5 ms |
8280 KB |
Output is correct |
18 |
Correct |
5 ms |
8280 KB |
Output is correct |
19 |
Correct |
26 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8280 KB |
Output is correct |
2 |
Correct |
3 ms |
8280 KB |
Output is correct |
3 |
Correct |
3 ms |
8280 KB |
Output is correct |
4 |
Correct |
3 ms |
8280 KB |
Output is correct |
5 |
Correct |
3 ms |
8280 KB |
Output is correct |
6 |
Correct |
3 ms |
8280 KB |
Output is correct |
7 |
Correct |
4 ms |
8284 KB |
Output is correct |
8 |
Correct |
5 ms |
8280 KB |
Output is correct |
9 |
Correct |
5 ms |
8280 KB |
Output is correct |
10 |
Correct |
5 ms |
8284 KB |
Output is correct |
11 |
Correct |
5 ms |
8284 KB |
Output is correct |
12 |
Correct |
5 ms |
8280 KB |
Output is correct |
13 |
Correct |
26 ms |
8512 KB |
Output is correct |
14 |
Correct |
5 ms |
8284 KB |
Output is correct |
15 |
Correct |
5 ms |
8432 KB |
Output is correct |
16 |
Correct |
5 ms |
8280 KB |
Output is correct |
17 |
Correct |
5 ms |
8280 KB |
Output is correct |
18 |
Correct |
5 ms |
8280 KB |
Output is correct |
19 |
Correct |
26 ms |
8280 KB |
Output is correct |
20 |
Correct |
9 ms |
8284 KB |
Output is correct |
21 |
Correct |
8 ms |
8536 KB |
Output is correct |
22 |
Correct |
8 ms |
8280 KB |
Output is correct |
23 |
Correct |
10 ms |
8280 KB |
Output is correct |
24 |
Correct |
11 ms |
8280 KB |
Output is correct |
25 |
Correct |
88 ms |
8280 KB |
Output is correct |