Show problems as
Classic problem #3733MediumMathBinary Search

Minimum Time to Complete All Deliveries

Real-world version: Two Vans Making Every Drop
Tracked in this browser only
Read Minimum Time to Complete All Deliveries on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

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