#BS0000351. Đường đến rạp chiếu phim (Road to Cinema)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đường đến rạp chiếu phim (Road to Cinema)
Road to Cinema
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Vasya wants to travel from a car rental service to a cinema before his film starts in minutes. The straight road is km long, from coordinate to coordinate . There are fuel stations where refuelling is free and instantaneous, subject to the tank capacity.
The rental service has cars. Car costs to rent and has a tank holding litres. Each car starts with a full tank. Vasya can switch between the following driving modes whenever he wants:
- Normal: one kilometre takes minutes and uses litre of fuel.
- Accelerated: one kilometre takes minute and uses litres of fuel.
Determine the cheapest rental that allows Vasya to arrive no later than the start of the film.
Input
- The first line contains integers : the numbers of cars and fuel stations, the road length in km and the time available in minutes.
- Each of the following lines gives , the rental price and tank capacity of car .
- The last line contains the station coordinates in arbitrary order.
Output
Print the minimum rental price as an integer, or -1 if no car can meet the deadline.
Subtasks
- Subtask 1 (20 points): ; ; ; ; for all ; for all ; the are pairwise distinct.
- Subtask 2 (30 points): ; ; ; ; for all ; for all ; the are pairwise distinct.
- Subtask 3 (50 points): ; ; ; ; for all ; for all ; the are pairwise distinct.
Examples
Input 1
3 1 8 10
10 8
5 7
11 9
3
Output 1
10
Explanation
The station divides the road into lengths and . The car costing can drive the first km in accelerated mode in minutes using litres. After refuelling, it drives km normally and km accelerated, taking minutes and using litres. Total: minutes. The cheaper car has only litres; at most km of the second leg can be accelerated, so the trip takes at least minutes. The remaining car is more expensive.
Input 2
2 2 10 18
10 4
20 6
5 3
Output 2
20
Explanation
The legs have lengths . The car costing cannot cross the final km with a -litre tank. With the car costing , the first two legs take minutes in accelerated mode. On the last leg, accelerating for km and driving normally for km uses litres and takes minutes. Total time is , within .