CF988F.Rain and Umbrellas

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Polycarp lives on a coordinate line at the point x=0x = 0 . He goes to his friend that lives at the point x=ax = a . Polycarp can move only from left to right, he can pass one unit of length each second.

Now it's raining, so some segments of his way are in the rain. Formally, it's raining on nn non-intersecting segments, the ii -th segment which is in the rain is represented as [li,ri][l_i, r_i] ( 0li<ria0 \le l_i < r_i \le a ).

There are mm umbrellas lying on the line, the ii -th umbrella is located at point xix_i ( 0xia0 \le x_i \le a ) and has weight pip_i . When Polycarp begins his journey, he doesn't have any umbrellas.

During his journey from x=0x = 0 to x=ax = a Polycarp can pick up and throw away umbrellas. Polycarp picks up and throws down any umbrella instantly. He can carry any number of umbrellas at any moment of time. Because Polycarp doesn't want to get wet, he must carry at least one umbrella while he moves from xx to x+1x + 1 if a segment [x,x+1][x, x + 1] is in the rain (i.e. if there exists some ii such that lixl_i \le x and x+1rix + 1 \le r_i ).

The condition above is the only requirement. For example, it is possible to go without any umbrellas to a point where some rain segment starts, pick up an umbrella at this point and move along with an umbrella. Polycarp can swap umbrellas while he is in the rain.

Each unit of length passed increases Polycarp's fatigue by the sum of the weights of umbrellas he carries while moving.

Can Polycarp make his way from point x=0x = 0 to point x=ax = a ? If yes, find the minimum total fatigue after reaching x=ax = a , if Polycarp picks up and throws away umbrellas optimally.

输入格式

The first line contains three integers aa , nn and mm ( 1a,m2000,1na21 \le a, m \le 2000, 1 \le n \le \lceil\frac{a}{2}\rceil ) — the point at which Polycarp's friend lives, the number of the segments in the rain and the number of umbrellas.

Each of the next nn lines contains two integers lil_i and rir_i ( 0li<ria0 \le l_i < r_i \le a ) — the borders of the ii -th segment under rain. It is guaranteed that there is no pair of intersecting segments. In other words, for each pair of segments ii and jj either ri<ljr_i < l_j or rj<lir_j < l_i .

Each of the next mm lines contains two integers xix_i and pip_i ( 0xia0 \le x_i \le a , 1pi1051 \le p_i \le 10^5 ) — the location and the weight of the ii -th umbrella.

输出格式

Print "-1" (without quotes) if Polycarp can't make his way from point x=0x = 0 to point x=ax = a . Otherwise print one integer — the minimum total fatigue after reaching x=ax = a , if Polycarp picks up and throws away umbrellas optimally.

输入输出样例

  • 输入#1

    10 2 4
    3 7
    8 10
    0 10
    3 4
    8 1
    1 2
    

    输出#1

    14
    
  • 输入#2

    10 1 1
    0 9
    0 5
    

    输出#2

    45
    
  • 输入#3

    10 1 1
    0 9
    1 5
    

    输出#3

    -1
    

说明/提示

In the first example the only possible strategy is to take the fourth umbrella at the point x=1x = 1 , keep it till the point x=7x = 7 (the total fatigue at x=7x = 7 will be equal to 1212 ), throw it away, move on from x=7x = 7 to x=8x = 8 without an umbrella, take the third umbrella at x=8x = 8 and keep it till the end (the total fatigue at x=10x = 10 will be equal to 1414 ).

In the second example the only possible strategy is to take the first umbrella, move with it till the point x=9x = 9 , throw it away and proceed without an umbrella till the end.

首页