Submission #1035519

#TimeUsernameProblemLanguageResultExecution timeMemory
1035519JethroHolding (COCI20_holding)C++14
110 / 110
172 ms208112 KiB
//Written by: Jethro_ //---------------------- #include <bits/stdc++.h> using namespace std; int n, l, r, k; void solve() { cin >> n >> l >> r >> k; vector<int> a(n + 1); for (int i = 1; i <= n; ++i) { cin >> a[i]; } int m = (r - l + 1); vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(k + 1, 1e9))); int res = 1e9; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= k; ++j) { dp[i][0][j] = 0; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { for (int p = 0; p <= k; ++p) { dp[i][j][p] = dp[i - 1][j][p]; if (p - abs(i - (l + j - 1)) >= 0) { dp[i][j][p] = min({dp[i][j][p], dp[i - 1][j - 1][p - abs(i - (l + j - 1))] + a[i]}); } if (j == m) res = min(res, dp[i][m][p]); } } } cout << res; } int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); solve(); } //dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j - 1][k], dp[i - 1][j - 1][k + abs(j - i)] - a[i] + a[j]);
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...