/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
const int N = 1e4+15, M = 110, F = 2147483646, K = 20;
int n, l, r, k, arr[M], dp[M][M][N];
void solve(){
cin >> n >> l >> r >> k;
for(int i = 1; i <= n; ++i) cin >> arr[i];
int sum = 0;
for(int i = l; i <= r; ++i) sum += arr[i];
for(int i = 0; i <= n; ++i){
for(int j = 0; j <= n; ++j){
for(int l = 0; l <= k; ++l) dp[i][j][l] = sum;
}
}
vector<pair<int, int>> a;
vector<pair<int, int>> b;
for(int i = 1; i <= n; ++i){
if(i < l || i > r) a.pb({arr[i], i});
else b.pb({arr[i], i});
}
int ans = sum;
for(int i = 1; i <= a.size(); ++i){
for(int j = 1; j <= b.size(); ++j){
int dist = abs(a[i - 1].second - b[j - 1].second);
for(int l = 0; l <= k; ++l){
dp[i][j][l] = dp[i - 1][j][l];
if(l >= dist){
// cout << i << ' ' << j << ' ' << l << ' ' << dp[i][j][l] << ' ' << (a[i - 1].first - b[j - 1].first) << '\n';
dp[i][j][l] = min(dp[i][j][l], dp[i - 1][j - 1][l - dist] + (a[i - 1].first - b[j - 1].first));
}
//
ans = min(ans, dp[i][j][l]);
}
}
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
}
return 0;
}
Compilation message
holding.cpp: In function 'void solve()':
holding.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i = 1; i <= a.size(); ++i){
| ~~^~~~~~~~~~~
holding.cpp:35:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int j = 1; j <= b.size(); ++j){
| ~~^~~~~~~~~~~
holding.cpp: In function 'int main()':
holding.cpp:55:16: warning: unused variable 'aa' [-Wunused-variable]
55 | int T = 1, aa;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
1096 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
4 ms |
6988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
1096 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
4 ms |
6988 KB |
Output is correct |
8 |
Incorrect |
7 ms |
11596 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
1096 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
4 ms |
6988 KB |
Output is correct |
8 |
Incorrect |
7 ms |
11596 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
1096 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
4 ms |
6988 KB |
Output is correct |
8 |
Incorrect |
7 ms |
11596 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |