8VC Venture Cup 2016 - Final Round (Div. 1 Edition)
D
Package Delivery
Codeforces
未评级
原题
← CE →
翻译中…

Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point $0$ on a number line, and the district center is located at the point $*d*$.

翻译中…

Johnny's truck has a gas tank that holds exactly $*n*$ liters, and his tank is initially full. As he drives, the truck consumes exactly one liter per unit distance traveled. Moreover, there are $*m*$ gas stations located at various points along the way to the district center. The $*i*$-th station is located at the point $*x*_{*i*}$ on the number line and sells an unlimited amount of fuel at a price of $*p*_{*i*}$ dollars per liter. Find the minimum cost Johnny must pay for fuel to successfully complete the delivery.

翻译中…

Input

翻译中…

The first line of input contains three space separated integers $*d*$, $*n*$, and $*m*$ ($1 ≤ *n* ≤ *d* ≤ 10^{9}$, $1 ≤ *m* ≤ 200 000$) — the total distance to the district center, the volume of the gas tank, and the number of gas stations, respectively.

翻译中…

Each of the next $*m*$ lines contains two integers $*x*_{*i*}$, $*p*_{*i*}$ ($1 ≤ *x*_{*i*} ≤ *d* - 1$, $1 ≤ *p*_{*i*} ≤ 10^{6}$) — the position and cost of gas at the $*i*$-th gas station. It is guaranteed that the positions of the gas stations are distinct.

翻译中…

Output

翻译中…

Print a single integer — the minimum cost to complete the delivery. If there is no way to complete the delivery, print -1.

翻译中…

Note

翻译中…

In the first sample, Johnny's truck holds $4$ liters. He can drive $3$ units to the first gas station, buy $2$ liters of gas there (bringing the tank to $3$ liters total), drive $3$ more units to the third gas station, buy $4$ liters there to fill up his tank, and then drive straight to the district center. His total cost is $2·5 + 4·3 = 22$ dollars.

翻译中…

In the second sample, there is no way for Johnny to make it to the district center, as his tank cannot hold enough gas to take him from the latest gas station to the district center.

翻译中…

样例

Input #1
10 4 4
3 5
5 8
6 3
8 4
Output #1
22
InputCopy OutputCopy
Input #2
16 5 2
8 2
5 1
Output #2
-1
InputCopy OutputCopy
题目信息
题号
634D
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。