Submission #111946

#TimeUsernameProblemLanguageResultExecution timeMemory
111946fredbrSličice (COCI19_slicice)C++17
90 / 90
164 ms1456 KiB
#include <bits/stdc++.h> using namespace std; int const maxn = 505; int n, m, k; int b[maxn], p[maxn]; int dp[maxn][maxn]; int solve(int resta, int at) { if (at == n+1) return 0; if (dp[resta][at] >= 0) return dp[resta][at]; int& d = dp[resta][at]; d = 0; for (int i = p[at]; i <= m and i-p[at] <= resta; i++) { d = max(d, b[i] + solve(resta-i+p[at], at+1)); } return d; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); cin >> n >> m >> k; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 0; i <= m; i++) cin >> b[i]; memset(dp, -1, sizeof(dp)); int ans = solve(k, 1); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...