#pragma GCC optimize("O3", "inline")
#define skillissue <bits/stdc++.h>
#define ultra_mal std
#include skillissue
using namespace ultra_mal;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ins insert
#define pb push_back
#define int long long int
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
#define hash FhashF
const int mod = 1e9 +7, sze = 1e4 +10, inf = LLONG_MAX, P = 1453;
// const int L = 30;
int dp[111][111][sze];
void optimus(){
int n,l,r,k;
cin>>n>>l>>r>>k;
vector<int> arr(n+1);
for(int i=1;i<=n;i++){
cin>>arr[i];
}
int sum=0;
for(int i = l;i<=r;i++){
sum+=arr[i];
}
dp[1][l][0]=0;
for(int i =1;i<l;i++){
for(int j= l;j<=r;j++){
for(int p=0;p<=k;p++){
dp[i][j][p]= max({
dp[i-1][j][p],
dp[i][j-1][p],
(int)0
});
if((j-i)<=p){
dp[i][j][p]=max(dp[i][j][p],dp[i-1][j-1][p - (j-i)] + arr[j]-arr[i]);
}
// cout<<i<<" "<<j<<" "<<p<<" "<<dp[i][j][p]<<" "<<
// dp[i-1][j-1][p - (j-i)]+ arr[i]- arr[j]<<endl;
}
}
}
drop(sum - dp[l-1][r][k]);
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tt = 1;
// cin>>tt;
while(tt--){
optimus();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
3 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
2140 KB |
Output is correct |
13 |
Correct |
29 ms |
49492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
3 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
2140 KB |
Output is correct |
13 |
Correct |
29 ms |
49492 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
1372 KB |
Output is correct |
16 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
3 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
2140 KB |
Output is correct |
13 |
Correct |
29 ms |
49492 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
1372 KB |
Output is correct |
16 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |