Submission #868258

#TimeUsernameProblemLanguageResultExecution timeMemory
868258hungntHolding (COCI20_holding)C++14
22 / 110
1 ms4560 KiB
#include <bits/stdc++.h> using namespace std; const int N = 52; int n, L, R, k; int a[102]; int dp[N][1500][N]; void MAX(int &A, int B) { if(A < B) A = B; } void sub2(int L) { k = min(k, n * n / 2); for(int i = L; i <= R; i++) for(int c = 1; c <= k; c++) for(int j = 1; j <= L - 1; j++) dp[i][c][j] = 0; int ans = 0; for(int i = L; i <= R; i++) for(int c = 1; c <= k; c++) for(int j = L - 1; j > 0; j--) { MAX(dp[i][c][j], dp[i - 1][c][j]); MAX(dp[i][c][j], dp[i][c][j - 1]); if(c - i + j >= 0) { MAX(dp[i][c][j], dp[i - 1][c - i + j][j - 1] + a[i] - a[j]); MAX(dp[i][c][j], dp[i - 1][c - i + j][j]); // cout << i << " " << j << " " << c << " " << dp[i][c][j] << "\n"; } ans = max(ans, dp[i][c][j]); } // cout << ans << "\n"; for(int i = L; i <= R; i++) ans -= a[i]; cout << -ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> L >> R >> k; for(int i = 1; i <= n; i++) cin >> a[i]; if(R == n) { sub2(L); return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...