Help..!! <Nutanix>

0

0 votes
Open, Sorting, hiring, Priority queue, Algorithms, Medium, Greedy algorithm, Open, Greedy algorithm, Greedy algorithm
Problem

You are traveling through a car to your destination. The car is D units from your destination. There are N petrol stations between your current location and destination. 

You are required to reach the destination by making the minimum possible number of stops on the way to your destination. The capacity of the petrol tank is large as there is no limit to the amount of petrol it can store. The car contains some initial amount of petrol in the tank that is denoted by P

Determine the minimum number of stops that is required to reach the destination or whether you can reach the destination.

Note:
Your destination is situated at coordinate 0. All the other distances are given with respect to the destination's location.

Input format

  • First line: An integer N denoting the number of petrol stations on the way to your destination
  • Each of the next N lines: Two space-separated integers S and F denoting the distance from the destination to the station and the amount of petrol available at that station respectively
  • Next line: Two space-separated integers D and P

Output format

Print a single integer denoting the minimum number of stops that is required to reach the destination. If it is not possible to reach the destination, then print 1.

Constraints

1N105

1D,P,S,F109

Sample Input
4
3 15
6 4
8 5
15 6
20 17
Sample Output
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

There are 4 petrol stations on the way to town at distance 3, 6, 8, 15 from the town. These fuel stops can supply up to 15, 4, 5, and 6 units of petrol, respectively. The car is currently located 20 units away from the town. The car has 17 units of petrol initially.

Car drives 17 units and stops at station at distance 3 from the town to acquire petrol and drives to the town. Thus minimum number of stops required to drive to the town is 1.

Editor Image

?