""" maximum_fruits.py """

# https://leetcode.com/problems/maximum-fruits-harvested-after-at-most-k-steps/description/

# usage: python3 maximum_fruits.py


def max_harvest(locs, start, steps):
    """ maximum harvest """
    maximum = 0
    for i in range(steps + 1):
        x1, x2 = start - i, steps - i - i + start
        harvest = sum(k for j, k in locs if x1 <= j <= x2)
        maximum = max(maximum, harvest)

    return maximum


fruits = [[2, 8], [6, 3], [8, 6]]
assert max_harvest(fruits, 5, 4) == 9

fruits = [[0, 9], [4, 1], [5, 7], [6, 2], [7, 4], [10, 9]]
assert max_harvest(fruits, 5, 4) == 14

fruits = [[0, 3], [6, 4], [8, 5]]
assert max_harvest(fruits, 3, 2) == 0
