n days in a row. On day i (0-based) you pick harvest[i] berries from it, and they stay fresh for shelf_life[i] days: on day i + shelf_life[i] they have already gone bad. On days with no berries, harvest[i] = 0 and shelf_life[i] = 0.
You eat at most one berry a day, and you may keep eating after the bush stops bearing fruit. Return the largest number of berries you can eat.harvest=[2, 3], shelf_life=[5, 1] → 3
Berries from the first picking are good on days 0–4, from the second only on day 1. On day 0 eat one from the first picking, on day 1 one from the second (its other two go bad), on day 2 the last one from the first. That is 3.
harvest=[1, 0, 0, 2], shelf_life=[1, 0, 0, 4] → 3
The single berry of day 0 is eaten right away. Days 1 and 2 have nothing to eat. The two berries of day 3 stay good until day 6 and are eaten on days 3 and 4.
harvest=[4, 1, 1], shelf_life=[2, 4, 1] → 4
harvest[i], shelf_life[i] ≤ 2 · 10⁴shelf_life[i] = 0 if and only if harvest[i] = 0harvest=[2, 3], shelf_life=[5, 1]
3
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.