CF988F.Rain and Umbrellas

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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] (0≤li<ri≤a0 \le l_i \lt r_i \le a).

There are mm umbrellas lying on the line, the ii-th umbrella is located at point xix_i (0≤xi≤a0 \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 li≤xl_i \le x and x+1≤rix + 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.

Polycarp 生活在坐标轴上的点 x=0x = 0 处。他要前往住在点 x=ax = a 的朋友家。Polycarp 只能从左向右移动,每秒恰好移动一个单位长度。

此时正在下雨,因此他路径上的一些区间处于雨中。形式化地说,共有 nn 个互不相交的雨中区间,其中第 ii 个雨中区间表示为 [li,ri][l_i, r_i](满足 0≤li<ri≤a0 \le l_i \lt r_i \le a)。

直线上还散落着 mm 把雨伞,第 ii 把雨伞位于点 xix_i(满足 0≤xi≤a0 \le x_i \le a),重量为 pip_i。Polycarp 出发时手中没有任何雨伞。

在从 x=0x = 0 到 x=ax = a 的旅途中,Polycarp 可以拾取和丢弃雨伞。他拾取或丢弃任意一把雨伞均瞬时完成。在任意时刻,他可携带任意数量的雨伞。由于 Polycarp 不想被淋湿,因此当他从 xx 移动到 x+1x + 1 时,若单位区间 [x,x+1][x, x + 1] 完全处于雨中(即存在某个 ii 满足 li≤xl_i \le x 且 x+1≤rix + 1 \le r_i),则他必须至少携带一把雨伞。

上述条件是唯一约束。例如,他可以不带任何雨伞走到某段雨区的起点位置,在该点拾起一把雨伞,然后持伞继续前进;Polycarp 也可以在雨中更换所持的雨伞。

每移动一个单位长度,Polycarp 的疲劳值将增加他当前所持所有雨伞的重量之和。

Polycarp 能否从点 x=0x = 0 成功到达点 x=ax = a?如果可以,请找出他在最优地拾取与丢弃雨伞的前提下,抵达 x=ax = a 时的最小总疲劳值。

输入格式

The first line contains three integers aa, nn and mm (1≤a,m≤2000,1≤n≤⌈a2⌉1 \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 (0≤li<ri≤a0 \le l_i \lt 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 \lt l_j or rj<lir_j \lt l_i.

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

第一行包含三个整数 aa、nn 和 mm(1≤a,m≤20001 \le a, m \le 2000,1≤n≤⌈a2⌉1 \le n \le \lceil\frac{a}{2}\rceil)——分别表示 Polycarp 的朋友所居住的位置、雨区线段的数量以及雨伞的数量。

接下来的 nn 行中,每行包含两个整数 lil_i 和 rir_i(0≤li<ri≤a0 \le l_i \lt r_i \le a)——表示第 ii 个雨区线段的左右端点。保证任意两个雨区线段互不相交。换言之,对任意两个线段 ii 和 jj,均有 ri<ljr_i \lt l_j 或 rj<lir_j \lt l_i。

再接下来的 mm 行中,每行包含两个整数 xix_i 和 pip_i(0≤xi≤a0 \le x_i \le a,1≤pi≤1051 \le p_i \le 10^5)——分别表示第 ii 把雨伞的位置及其重量。

输出格式

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.

如果 Polycarp 无法从点 x=0x = 0 到达点 x=ax = a,则输出 \-1(不带引号)。否则,输出一个整数——即 Polycarp 在最优地拾取和丢弃雨伞的前提下,到达 x=ax = a 时的最小总疲劳值。

输入输出样例

  • 输入#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.

在第一个例子中,唯一可行的策略是:在位置 x=1x = 1 处取第四把伞,一直携带至位置 x=7x = 7(此时在 x=7x = 7 处的总疲劳值为 1212),然后丢弃该伞;接着从 x=7x = 7 移动到 x=8x = 8 且不携带伞;在 x=8x = 8 处取第三把伞,并一直携带至终点(此时在 x=10x = 10 处的总疲劳值为 1414)。

在第二个例子中,唯一可行的策略是:取第一把伞,携带它移动至位置 x=9x = 9,然后丢弃该伞,并在剩余路程中不携带伞直至终点。

输入解题思路,AI测评打分。不知道怎么写?

首页