Park Benches Park Benches
Undefined
English

You will need to remove some benches to keep the social distance.

You are given two arguments:

  1. A list of the bench's detail (a tuple of the leftmost coordinate and the length).
  2. The minimum social distance between benches.

In order to make sure that the distance between benches is at least the social distance, we remove some benches. What is the maximum total length of the remaining benches?

NOTE:

  • A list of the bench's detail is sorted.

Example:

park_benches([(0, 2), (3, 3)], 2) == 3                  # [(3, 3)]
park_benches([(1, 3), (6, 5), (13, 4)], 3) == 7         # [(1, 3), (13, 4)]
park_benches([(1, 2), (5, 6), (13, 3)], 3) == 6         # [(5, 6)]

Input: Two arguments:

  1. A list of tuples of two integers.
  2. An integer.

Output: An integer.

Precondition:

  • 1 ≤ len(benches) ≤ 100