Sleeping Schedule
MediumRating 1700Codeforces2-D Dynamic Programming
Approach hintTry it first, then revealHide
The start time of a sleep depends only on how many earlier sleeps were shortened. Let dp[i][j] be the most good sleeps among the first i with j shortened; sleep i starts at the prefix sum minus j, modulo h.