bushes, where bushes[i] = [position, amount] means amount berries grow at point position. The list is sorted by position in increasing order, and all positions are distinct.
You stand at point start and may take at most steps steps. A step moves you one unit left or right, and you may change direction as often as you like. At every point you visit (including start) you pick all the berries; they do not grow back.
Return the largest number of berries you can pick.bushes=[[1, 4], [3, 2], [9, 5]], start=4, steps=5 → 6
Walk left: position 3 (2 berries), then position 1 (4 berries), 3 steps for 6 berries. Reaching position 9 takes 5 steps and yields only 5.
bushes=[[2, 3], [5, 1], [8, 6]], start=5, steps=6 → 7
Walk right to 8: 3 steps for 1 + 6 = 7 berries. Getting from there to 2 would take 6 more steps, which you do not have. Going left to 2 and back gives only 3 + 1 = 4.
bushes=[[10, 7]], start=0, steps=3 → 0
bushes=[[1, 4], [3, 2], [9, 5]], start=4, steps=5
6
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.