#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 105;
const int M = 10005;
const int inf = 1e18 + 7;
int dp[M+1][N+1],ndp[M+1][N+1];//0 indexli , kaç kumam kaldı , kaç tane eleman aldım
void solve(){
int n,l,r,k;cin >> n >> l >> r >> k;
l--;r--;
int arr[n];
for(int i = 0;i<n;i++)cin >> arr[i];
for(int j = 0;j<=M;j++){
for(int t = 0;t<=N;t++){
dp[j][t] = inf;
ndp[j][t] = inf;
}
}
dp[k][0] = 0;
for(int i = 0;i<n;i++){
for(int j = 0;j<=k;j++){
for(int t = 0;t<=(r-l+1);t++){
if(dp[j][t] == inf)continue;
//cout << i << " " << j << " " << k << " = " << dp[i][j][k] << " " << (j - abs((l + k) - i)) << endl;
//al
if((j - abs((l + t) - i)) >= 0){
ndp[(j - abs((l + t) - i))][t+1] = min(ndp[(j - abs((l + t) - i))][t+1] , dp[j][t] + arr[i]);
//cout << " -> " << i+1 << " " << (j - abs((l + k) - i)) << " " << k+1 << " = " << dp[i+1][(j - abs((l + k) - i))][k+1] << endl;
}
//alma
ndp[j][t] = min(ndp[j][t] , dp[j][t]);
}
}
for(int j = 0;j<=M;j++){
for(int t = 0;t<=N;t++){
dp[j][t] = ndp[j][t];
}
}
}
int ans = inf;
//cout << "ENDED" << endl;
for(int i = 0;i<=k;i++){
//cout << n << " " << i << " " << r-l+1 << " -> " << dp[n][i][r-l+1] << endl;
ans = min(ans , dp[i][r-l+1]);
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
16988 KB |
Output is correct |
2 |
Correct |
7 ms |
16988 KB |
Output is correct |
3 |
Correct |
7 ms |
17052 KB |
Output is correct |
4 |
Correct |
12 ms |
16988 KB |
Output is correct |
5 |
Correct |
7 ms |
16988 KB |
Output is correct |
6 |
Correct |
7 ms |
16988 KB |
Output is correct |
7 |
Correct |
9 ms |
17048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
16988 KB |
Output is correct |
2 |
Correct |
7 ms |
16988 KB |
Output is correct |
3 |
Correct |
7 ms |
17052 KB |
Output is correct |
4 |
Correct |
12 ms |
16988 KB |
Output is correct |
5 |
Correct |
7 ms |
16988 KB |
Output is correct |
6 |
Correct |
7 ms |
16988 KB |
Output is correct |
7 |
Correct |
9 ms |
17048 KB |
Output is correct |
8 |
Correct |
21 ms |
16936 KB |
Output is correct |
9 |
Correct |
30 ms |
17060 KB |
Output is correct |
10 |
Correct |
22 ms |
16984 KB |
Output is correct |
11 |
Correct |
32 ms |
17240 KB |
Output is correct |
12 |
Correct |
19 ms |
16988 KB |
Output is correct |
13 |
Correct |
56 ms |
17236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
16988 KB |
Output is correct |
2 |
Correct |
7 ms |
16988 KB |
Output is correct |
3 |
Correct |
7 ms |
17052 KB |
Output is correct |
4 |
Correct |
12 ms |
16988 KB |
Output is correct |
5 |
Correct |
7 ms |
16988 KB |
Output is correct |
6 |
Correct |
7 ms |
16988 KB |
Output is correct |
7 |
Correct |
9 ms |
17048 KB |
Output is correct |
8 |
Correct |
21 ms |
16936 KB |
Output is correct |
9 |
Correct |
30 ms |
17060 KB |
Output is correct |
10 |
Correct |
22 ms |
16984 KB |
Output is correct |
11 |
Correct |
32 ms |
17240 KB |
Output is correct |
12 |
Correct |
19 ms |
16988 KB |
Output is correct |
13 |
Correct |
56 ms |
17236 KB |
Output is correct |
14 |
Correct |
32 ms |
16988 KB |
Output is correct |
15 |
Correct |
20 ms |
16988 KB |
Output is correct |
16 |
Correct |
19 ms |
16988 KB |
Output is correct |
17 |
Correct |
19 ms |
16988 KB |
Output is correct |
18 |
Correct |
20 ms |
16988 KB |
Output is correct |
19 |
Correct |
66 ms |
17040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
16988 KB |
Output is correct |
2 |
Correct |
7 ms |
16988 KB |
Output is correct |
3 |
Correct |
7 ms |
17052 KB |
Output is correct |
4 |
Correct |
12 ms |
16988 KB |
Output is correct |
5 |
Correct |
7 ms |
16988 KB |
Output is correct |
6 |
Correct |
7 ms |
16988 KB |
Output is correct |
7 |
Correct |
9 ms |
17048 KB |
Output is correct |
8 |
Correct |
21 ms |
16936 KB |
Output is correct |
9 |
Correct |
30 ms |
17060 KB |
Output is correct |
10 |
Correct |
22 ms |
16984 KB |
Output is correct |
11 |
Correct |
32 ms |
17240 KB |
Output is correct |
12 |
Correct |
19 ms |
16988 KB |
Output is correct |
13 |
Correct |
56 ms |
17236 KB |
Output is correct |
14 |
Correct |
32 ms |
16988 KB |
Output is correct |
15 |
Correct |
20 ms |
16988 KB |
Output is correct |
16 |
Correct |
19 ms |
16988 KB |
Output is correct |
17 |
Correct |
19 ms |
16988 KB |
Output is correct |
18 |
Correct |
20 ms |
16988 KB |
Output is correct |
19 |
Correct |
66 ms |
17040 KB |
Output is correct |
20 |
Correct |
59 ms |
16988 KB |
Output is correct |
21 |
Correct |
57 ms |
16988 KB |
Output is correct |
22 |
Correct |
37 ms |
16984 KB |
Output is correct |
23 |
Correct |
57 ms |
17044 KB |
Output is correct |
24 |
Correct |
38 ms |
16984 KB |
Output is correct |
25 |
Correct |
106 ms |
17036 KB |
Output is correct |