Tap here to switch tabs
Problem
Submissions

Problem: Minimum Speed to Arrive on Time

Try to solve the Minimum Speed to Arrive on Time problem.

Statement

You are given a floating point value hour, representing the total time available to reach your destination, and an integer array dist of length n, where dist[i] represents the distance of the iith train ride.

Each train can only depart at an integer hour, which means you may have to wait before boarding the next train. For example, if a train journey takes 1.51.5 hours, you must wait an additional 0.50.5 hours to depart on the next train at the 22 hour mark. The final train ride does not require any waiting time after arriving at the destination.

Return the minimum positive integer speed that all trains must maintain to arrive within hour hours. If it is impossible to reach the destination on time, return −1-1.

Constraints:

  • n == dist.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq dist[i] ≤105\leq 10^5

  • 1≤1 \leq hour ≤109\leq 10^9

  • There will be at most 22 digits after the decimal point in hour.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Speed to Arrive on Time

Try to solve the Minimum Speed to Arrive on Time problem.

Statement

You are given a floating point value hour, representing the total time available to reach your destination, and an integer array dist of length n, where dist[i] represents the distance of the iith train ride.

Each train can only depart at an integer hour, which means you may have to wait before boarding the next train. For example, if a train journey takes 1.51.5 hours, you must wait an additional 0.50.5 hours to depart on the next train at the 22 hour mark. The final train ride does not require any waiting time after arriving at the destination.

Return the minimum positive integer speed that all trains must maintain to arrive within hour hours. If it is impossible to reach the destination on time, return −1-1.

Constraints:

  • n == dist.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq dist[i] ≤105\leq 10^5

  • 1≤1 \leq hour ≤109\leq 10^9

  • There will be at most 22 digits after the decimal point in hour.