Editorial for AYJCC24 P3 - Rohan's Club Heist
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
This problem requires dynamic programming to solve.
Subtask 1 [30%]
Let \(dp[i]\) be the maximum number of tickets one can rob in total from stall \(1\) to stall \(i\) if stall \(i\) was robbed.
Using a brute force approach to calculating \(dp\) values suffices. For index \(dp[i]\), loop from \(dp[1]\) to \(dp[i - p_{i} - 1]\), and take the best subproblem.
Time Complexity: \(O(N^{2})\)
Subtask 2 [70%]
We can optimize this by making a slight change to our \(dp\) definition. Let \(dp[i]\) be the maximum number of tickets one can rob in total from stall \(1\) to stall \(i\).
Calculating \(dp\) values now requires us to propogate the maximal \(dp\) value forward so that our \(dp\) definition holds. Now, the optimal subproblem is always the most forward index.
Time Complexity: \(O(N)\)
Comments