All problems
0975MediumMathBinary Search

Two Vans Making Every Drop

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3733Minimum Time to Complete All Deliveries

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

Two vans make deliveries. Van i has d[i] drops to make and needs r[i] minutes for each drop it makes.

The two vans work at the same time as each other. Either van may take over any number of the other's drops, so the drops may be shared out between them however you like, but every drop must be made.

Return the fewest minutes until all the drops are done, which is the longer of the two vans' working times.

Examples

Example 1

Input
d = [14, 27], r = [5, 3]
Output
78

There are 41 drops between them. In 63 minutes the first van manages 12 and the second 21, which is 33 and not enough; the smallest allowance that covers all 41 is what is returned.

Example 2

Input
d = [5, 5], r = [2, 2]
Output
10

Ten drops between two vans of the same speed means five each, at two minutes apiece.

Example 3

Input
d = [10, 1], r = [2, 7]
Output
18

Eleven drops in all. The fast van is worth more than three of the slow one's, so it takes most of them, and the two finish together as nearly as whole drops allow.

Constraints

  • d.length == 2
  • r.length == 2
  • 1 <= d[i] <= 10^9
  • 2 <= r[i] <= 3 * 10^4

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def minimum_time(d: list[int], r: list[int]) -> int:
Java
public long minimumTime(int[] d, int[] r)
September 7
Apply