이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |