Submission #237746

#TimeUsernameProblemLanguageResultExecution timeMemory
237746Haunted_CppFeast (NOI19_feast)C++17
41 / 100
96 ms37496 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2005; bool calc [N][N][2]; long long dp [N][N][2]; long long arr [N]; int n, k; long long solve (int p, int box, bool is) { if (box < 0) return -1e15; if (p >= n) return (box >= 0 ? 0 : -1e15); if (calc[p][box][is]) return dp[p][box][is]; long long &res = dp[p][box][is]; calc[p][box][is] = true; res = -1e15; if (!is) { res = max (res, solve (p + 1, box, false) ); res = max (res, solve (p + 1, box - 1, true) + arr[p]); } else { res = max (res, solve (p + 1, box, true) + arr[p]); res = max (res, solve (p + 1, box, false) ); } return res; } int main () { ios::sync_with_stdio(0); cin.tie(0); memset (calc, false, sizeof(calc)); cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; cout << solve (0, k, false) << '\n'; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...