PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000281. Vận tốc nhỏ nhất để đến đúng giờ (Minimum Speed to Arrive on Time)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Vận tốc nhỏ nhất để đến đúng giờ (Minimum Speed to Arrive on Time)
Minimum Speed to Arrive on Time
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Start at time zero and take train rides in order, of lengths kilometres. All trains travel at the same positive integer speed . Departures occur only at integer hours; transfers at an integer hour require no waiting. No waiting is required after the final ride. Find the smallest speed allowing arrival by hours, or if impossible.
Input
First line: and decimal . Second line: integers .
Output
Print the smallest positive integer speed, or .
Subtasks
- Subtask 1 (20 points): ; ; ; has at most two decimal places.
- Subtask 2 (30 points): ; ; ; ; has at most two decimal places.
- Subtask 3 (50 points): ; ; ; has at most two decimal places.
Examples
Input 1
3 2.70
1 3 2
Output 1
3
Explanation
Speed 2 needs 1+2+1 hours; speed 3 needs 1+1+2/3 hours, within the deadline.
Input 2
3 1.90
1 3 2
Output 2
-1
Explanation
The final ride cannot depart before hour 2.