#P1253E. Antenna Coverage
Antenna Coverage
No submission language available for this problem.
Description
The mayor of the Central Town wants to modernize Central Street, represented in this problem by the axis.
On this street, there are antennas, numbered from to . The -th antenna lies on the position and has an initial scope of : it covers all integer positions inside the interval .
It is possible to increment the scope of any antenna by , this operation costs coin. We can do this operation as much as we want (multiple times on the same antenna if we want).
To modernize the street, we need to make all integer positions from to inclusive covered by at least one antenna. Note that it is authorized to cover positions outside , even if it's not required.
What is the minimum amount of coins needed to achieve this modernization?
The first line contains two integers and ( and ).
The -th of the next lines contains two integers and ( and ).
On each position, there is at most one antenna (values are pairwise distinct).
You have to output a single integer: the minimum amount of coins required to make all integer positions from to inclusive covered by at least one antenna.
Input
The first line contains two integers and ( and ).
The -th of the next lines contains two integers and ( and ).
On each position, there is at most one antenna (values are pairwise distinct).
Output
You have to output a single integer: the minimum amount of coins required to make all integer positions from to inclusive covered by at least one antenna.
Samples
Note
In the first example, here is a possible strategy:
- Increase the scope of the first antenna by , so that it becomes . This antenna will cover interval which is
- Increase the scope of the second antenna by , so that it becomes . This antenna will cover interval , which is
- Increase the scope of the third antenna by , so that it becomes . This antenna will cover interval , which is
Total cost is . We can prove that it's the minimum cost required to make all positions from to covered by at least one antenna.
Note that positions and are in this solution covered by two different antennas, but it's not important.
—
In the second example, the first antenna already covers an interval so we have nothing to do.
Note that the only position that we needed to cover was position ; positions and are covered, but it's not important.