#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n"
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e18;
void solve()
{
int n,l,r,k;
cin >> n >> l >> r >> k;
vector<vector<int>> dp(r-l+5,vector<int>(k+1,INF));
vector<vector<int>> ndp(r-l+5,vector<int>(k+1,INF));
dp[0][0]=0;
int ar[n+1];
for(int i=1;i<=n;i++) cin >> ar[i];
for(int i=1;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
for(int z=0;z<=k;z++)
{
if(dp[j][z]==INF) continue;
// aldim
if(j+1<=r-l+1 && z+abs(i-(l+j)) <= k)
ndp[j+1][z+abs(i-(l+j))] = min( ndp[j+1][z+abs(i-(l+j))] , dp[j][z] + ar[i]);
// almadim
ndp[j][z] = min(ndp[j][z] , dp[j][z]);
}
}
dp=ndp;
ndp.assign(r-l+5,vector<int>(k+1,INF));
}
int ans=INF;
for(int i=0;i<=k;i++)
ans=min(ans,dp[r-l+1][i]);
cout << ans << endl;
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int t=1;//cin >> t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |