CF627C.Package Delivery

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

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

输入格式

The first line of input contains three space separated integers dd , nn , and mm ( 1<=n<=d<=1091<=n<=d<=10^{9} , 1<=m<=200 0001<=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 mm lines contains two integers xix_{i} , pip_{i} ( 1<=xi<=d11<=x_{i}<=d-1 , 1<=pi<=1061<=p_{i}<=10^{6} ) — the position and cost of gas at the ii -th gas station. It is guaranteed that the positions of the gas stations are distinct.

输出格式

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

输入输出样例

  • 输入#1

    10 4 4
    3 5
    5 8
    6 3
    8 4
    

    输出#1

    22
    
  • 输入#2

    16 5 2
    8 2
    5 1
    

    输出#2

    -1
    

说明/提示

In the first sample, Johnny's truck holds 44 liters. He can drive 33 units to the first gas station, buy 22 liters of gas there (bringing the tank to 33 liters total), drive 33 more units to the third gas station, buy 44 liters there to fill up his tank, and then drive straight to the district center. His total cost is 25+43=222·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.

首页