Gas Stations
InterviewTime limit1sMemory limit1024 MB
Given gas stations with positions and prices, a budget, and a tank capacity, find the farthest point the car can reach.
Problem
Michelle and Marie are taking a road trip in their car. They will drive along a long straight road with gas stations, numbered from 1 to in order along the road. At the start of the road, the car is in the city, and gas station 1 is at the same spot.
Gas station is kilometers from the beginning of the road and sells gas for dollars per liter. Gas can only be bought in whole liters. One liter of gas is enough to drive 1 unit of distance. The gas tank has a capacity of liters, and the tank starts empty.
Michelle and Marie have dollars to spend on gas. They do not plan to come back. How far along the road can they drive?
Input
The first line contains three integers , , and , the number of gas stations, the total budget in dollars, and the tank capacity in liters (; ; ).
Each of the next lines contains two integers and , the position of the -th gas station and its gas price (; ).
Output
Print one integer, the maximum distance that can be driven along the road.
Hint
In the sample test, they can buy 1 liter of gas at the first station and drive 1 unit. Then they buy 5 liters at the second station and drive 3 more units to reach the third station. At that point the tank holds 2 liters. They buy 1 more liter and drive 3 more units, ending the trip at distance 7.