#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
#define task "test"
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i, l, r) for( ll i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( ll i = (r) ; i >= (l) ; i-- )
#define sz(x) (int)x.size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define numBit(x) __builtin_popcount(x)
#define lb lower_bound
#define ub upper_bound
#define ar array
#define endl '\n'
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
const int N = 22;
const ll inf = 0x3f3f3f3f;
int n, l, r, k;
ll a[N];
int dp[N][N][10000];
int solve(int i, int j, int left) {
int &ret = dp[i][j][left];
if (ret != -1) return ret;
if (i >= j || j > r || i >= l) return 0;
if (j - i <= left)
ret = solve(i + 1, j + 1, left - (j - i)) + (a[j] - a[i]);
ret = max(ret, solve(i + 1, j, left));
ret = max(ret, solve(i, j + 1, left));
ret = max(ret, solve(i + 1, j + 1, left));
return ret;
}
int main() {
// fastIO;
scanf("%d %d %d %d", &n, &l, &r, &k);
--l, --r;
ll sum = 0;
memset(dp, -1, sizeof dp);
forw(i, 0, n) {
scanf("%lld", &a[i]);
if (i >= l && i <= r) sum += a[i];
}
printf("%lld", sum - solve(0, l, k));
}
Compilation message
holding.cpp: In function 'int main()':
holding.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | scanf("%d %d %d %d", &n, &l, &r, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%lld", &a[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19148 KB |
Output is correct |
2 |
Correct |
8 ms |
19148 KB |
Output is correct |
3 |
Correct |
8 ms |
19148 KB |
Output is correct |
4 |
Correct |
9 ms |
19160 KB |
Output is correct |
5 |
Correct |
8 ms |
19168 KB |
Output is correct |
6 |
Correct |
8 ms |
19156 KB |
Output is correct |
7 |
Correct |
10 ms |
19148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19148 KB |
Output is correct |
2 |
Correct |
8 ms |
19148 KB |
Output is correct |
3 |
Correct |
8 ms |
19148 KB |
Output is correct |
4 |
Correct |
9 ms |
19160 KB |
Output is correct |
5 |
Correct |
8 ms |
19168 KB |
Output is correct |
6 |
Correct |
8 ms |
19156 KB |
Output is correct |
7 |
Correct |
10 ms |
19148 KB |
Output is correct |
8 |
Runtime error |
25 ms |
38772 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19148 KB |
Output is correct |
2 |
Correct |
8 ms |
19148 KB |
Output is correct |
3 |
Correct |
8 ms |
19148 KB |
Output is correct |
4 |
Correct |
9 ms |
19160 KB |
Output is correct |
5 |
Correct |
8 ms |
19168 KB |
Output is correct |
6 |
Correct |
8 ms |
19156 KB |
Output is correct |
7 |
Correct |
10 ms |
19148 KB |
Output is correct |
8 |
Runtime error |
25 ms |
38772 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19148 KB |
Output is correct |
2 |
Correct |
8 ms |
19148 KB |
Output is correct |
3 |
Correct |
8 ms |
19148 KB |
Output is correct |
4 |
Correct |
9 ms |
19160 KB |
Output is correct |
5 |
Correct |
8 ms |
19168 KB |
Output is correct |
6 |
Correct |
8 ms |
19156 KB |
Output is correct |
7 |
Correct |
10 ms |
19148 KB |
Output is correct |
8 |
Runtime error |
25 ms |
38772 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |