#include<bits/stdc++.h>
using i64 = long long;
using namespace std;
const int maxn = 100;
const int maxk = 10000;
int a[maxn+2];
int n,L,R,k;
i64 dp1[maxn+2][maxn+2][maxk+2];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#define name "text"
// freopen(name".inp","r",stdin);
// freopen(name".out","w+",stdout);
cin >> n >> L >> R >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
i64 total = 0;
for (int i = L; i <= R; ++i) total += a[i];
//... BUILD FOR THE LEFT
i64 mx = 0;
for (int i = 1; i < L; ++i)
{
for (int j = L; j <= R; ++j)
{
for (int used = 0; used <= k; ++used)
{
if (used - abs(i - j) >= 0)
{
dp1[i][j][used] = min(dp1[i][j][used] , dp1[i - 1][j - 1][used - abs(i - j)] + a[i] - a[j]);
}
mx = min(mx , dp1[i][j][used]);
}
}
}
cout << total + mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |