PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000101. Ít lần tiếp nhiên liệu nhất (Minimum Number of Refueling Stops)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ít lần tiếp nhiên liệu nhất (Minimum Number of Refueling Stops)
Minimum Number of Refueling Stops
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A car drives from coordinate to destination , initially with units of fuel. It consumes one fuel unit per distance unit. There are stations listed in increasing order, station at providing fuel once when chosen. The tank has unlimited capacity. Arriving with zero fuel is allowed. Find the minimum number of refueling stops or -1 if impossible.
Input
Line 1 contains . The following lines contain in strictly increasing position order.
Output
Print the fewest stops, or -1 if the destination is unreachable.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input
100 10 4
10 60
20 30
30 30
60 40
Output
2
Explanation
The car can reach station , take fuel, then reach station and take more to reach . Two stops suffice; no single stop does.