Help..!!
Practice
0 (0 votes)
Open
Open
Open
Sorting
Greedy algorithms
Hiring
Priority queue
Algorithms
Medium
Greedy algorithm
Basics of greedy algorithms
Problem
95% Success 117 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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

\(1\le N \le 10^5 \)

\( 1 \le D,P,S,F \le 10^{9} \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
5 votes
Tags:
HardNumber TheoryAlgorithmsMathematicsOpenApproved
Points:30
5 votes
Tags:
ApprovedMathMediumOpen
Points:20
22 votes
Tags:
ApprovedData StructuresEasyOpenSorting