Submission #844566

#TimeUsernameProblemLanguageResultExecution timeMemory
844566vjudge1Holding (COCI20_holding)C++17
22 / 110
31 ms24924 KiB
#include <bits/stdc++.h> using namespace std; int dp[105][10005],dp2[105][10005]; int dplast[105][10005],dp2last[105][10005]; int dps[105][10005], dps2[105][10005]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, left, right, k; cin >> n >> left >> right >> k; vector<int> a(n+1); for (int i = 1; i <= n; i++) cin >> a[i]; int sum = 0; for (int i = left; i <= right; i++) sum+=a[i]; for(int l=0; l<100+5; l++){ for(int j=0; j<=k; j++){ dp[l][j]=dp2[l][j]=sum; dplast[l][j]=dp2last[l][j]=sum; dps[l][j]=dps2[l][j]=sum; } } int ans=sum; for(int i=1; i<=n; i++){ if(i>=left&&i<=right) continue; for(int l=left; l<=right; l++){ for(int j=abs(l-i); j<=k; j++){ dp[l][j] = min(dp[l-1][j], dp2last[l-1][j]); dp[l][j] = min(dp[l][j], dplast[l-1][j-abs(l-i)]-a[l]+a[i]); ans=min(ans, dp[l][j]); } } swap(dplast, dp); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...