City Travel

3.9

156 votes
Basic Programming, Basics of Implementation, Easy, Implementation
Problem

You are going from City A to City B. The distance between A and B is S km. In the most days, you can go at most X km one day. But there are N exceptions, in the Ti th day, you can go at most Yi km. You need to find out the minimum number of days required to reach city B from city A

Input Format

First line contains three integers, S,X,N(1S,X109,0N103).

The (i+1) th line contains two integers Ti,Yi(1Ti,Yi109).

It's guaranteed any two Ti are different. Note that Ti is not sorted.

Output Format

One integer represents the answer.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first day, you walked 5km.

In the second day, you walked 4km.

In the third day, you walked 5km.

In the fourth day, you walked 7km and arrived.

Editor Image

?