#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 1e2+2;
const int M = N*N/4+2;
const int inf = 1e9+7;
const ll mod = 998244353;
int n, t, m, k, ans, tong, a[N], dpr[N][N][M], dpl[N][N][M], l, r;
vector<pll> adj[N];
vector<ll> vi;
string s;
void sol()
{
cin >> n >> l >> r >> k;
for(int i =1 ; i <= n; i ++)
{
cin >> a[i];
if(i >= l && i <= r)tong += a[i];
}
k = min(k, n*n/4+2);
for(int i = l; i <= r; i ++)
{
for(int j = l-1; j > 0; j --)
{
for(int p = 0; p <= k; p ++)
{
dpl[i][j][p] = max(dpl[i-1][j][p], dpl[i][j+1][p]);
if(p)dpl[i][j][p] = max(dpl[i][j][p], dpl[i][j][p-1]);
if(i-j <= p)dpl[i][j][p] = max(dpl[i][j][p], dpl[i-1][j+1][p-i+j]+a[i]-a[j]);
//cout << i <<" "<<j<<" "<<p<<" "<<dpl[i][j][p]<<'\n';
}
}
}
for(int i = r; i >= l; i --)
{
for(int j = r+1; j <= n; j ++)
{
for(int p = 0; p <= k; p ++)
{
dpr[i][j][p] = max(dpr[i+1][j][p], dpr[i][j-1][p]);
if(p)dpr[i][j][p] = max(dpr[i][j][p], dpr[i][j][p-1]);
if(j-i <= p)dpr[i][j][p] = max(dpr[i][j][p], dpr[i+1][j-1][p+i-j]+a[i]-a[j]);
}
}
}
if(l > 1)ans = dpl[r][1][k];
if(r < n)ans = max(ans, dpr[l][n][k]);
if(l > 1 && r < n)
{
for(int i = l; i <= r; i ++)
{
for(int p = 0; p <= k; p ++)
ans = max(ans, dpl[i][1][p]+dpr[i+1][n][k-p]);
}
}
cout << tong-ans;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message
holding.cpp: In function 'int main()':
holding.cpp:74:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:75:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
2380 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
3020 KB |
Output is correct |
11 |
Correct |
3 ms |
3148 KB |
Output is correct |
12 |
Correct |
1 ms |
1996 KB |
Output is correct |
13 |
Correct |
5 ms |
4300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
2380 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
3020 KB |
Output is correct |
11 |
Correct |
3 ms |
3148 KB |
Output is correct |
12 |
Correct |
1 ms |
1996 KB |
Output is correct |
13 |
Correct |
5 ms |
4300 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
2 ms |
1600 KB |
Output is correct |
17 |
Correct |
1 ms |
1740 KB |
Output is correct |
18 |
Correct |
3 ms |
2764 KB |
Output is correct |
19 |
Correct |
4 ms |
4292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
2380 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
3020 KB |
Output is correct |
11 |
Correct |
3 ms |
3148 KB |
Output is correct |
12 |
Correct |
1 ms |
1996 KB |
Output is correct |
13 |
Correct |
5 ms |
4300 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
2 ms |
1600 KB |
Output is correct |
17 |
Correct |
1 ms |
1740 KB |
Output is correct |
18 |
Correct |
3 ms |
2764 KB |
Output is correct |
19 |
Correct |
4 ms |
4292 KB |
Output is correct |
20 |
Correct |
5 ms |
6220 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
3 ms |
4388 KB |
Output is correct |
23 |
Correct |
5 ms |
2240 KB |
Output is correct |
24 |
Correct |
10 ms |
12240 KB |
Output is correct |
25 |
Correct |
53 ms |
25896 KB |
Output is correct |