To solve this problem, you'll have to open it on the computer

Circular tour

Queues
medium
Score: 40

Suppose there is a circle. There are petrol pumps on that circle. Petrol pumps are numbered to (both inclusive). You have two pieces of information corresponding to each of the petrol pumps: (1) the amount of petrol that particular petrol pump will give, and (2) the distance from that petrol pump to the next petrol pump.

Initially, you have a tank of infinite capacity carrying no petrol. You can start the tour at any of the petrol pumps. Calculate the first point from where the truck will be able to complete the circle. Consider that the truck will stop at each of the petrol pumps. The truck will move one kilometer for each liter of petrol.

Input Format

The first line will contain the value of. The next lines will contain a pair of integers each, i.e. the amount of petrol that petrol pump will give and the distance between that petrol pump and the next petrol pump.

Output Format

An integer will be the smallest index of the petrol pump from which we can start the tour.

Example 1:

Input:
    3
    1 5
    10 3
    3 4
Output:
    1
Explanation:
    We can start the tour from the second petrol pump.
Submit code to see the your result here