305198: CF988F. Rain and Umbrellas
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Rain and Umbrellas
题意翻译
要从 $0$ 走到 $a$ ,有 $n$ 个区间是有雨的,给定 $m$ 把伞的位置和重量,在整点处可以捡起伞或者丢掉伞,每秒钟可以向右移动一个单位,代价是携带的伞的总重量,如果移动的单位是有雨的,则必须携带伞才能通过。求最小代价。题目描述
Polycarp lives on a coordinate line at the point $ x = 0 $ . He goes to his friend that lives at the point $ x = 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 $ n $ non-intersecting segments, the $ i $ -th segment which is in the rain is represented as $ [l_i, r_i] $ ( $ 0 \le l_i < r_i \le a $ ). There are $ m $ umbrellas lying on the line, the $ i $ -th umbrella is located at point $ x_i $ ( $ 0 \le x_i \le a $ ) and has weight $ p_i $ . When Polycarp begins his journey, he doesn't have any umbrellas. During his journey from $ x = 0 $ to $ x = 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 $ x $ to $ x + 1 $ if a segment $ [x, x + 1] $ is in the rain (i.e. if there exists some $ i $ such that $ l_i \le x $ and $ x + 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 = 0 $ to point $ x = a $ ? If yes, find the minimum total fatigue after reaching $ x = a $ , if Polycarp picks up and throws away umbrellas optimally.输入输出格式
输入格式
The first line contains three integers $ a $ , $ n $ and $ m $ ( $ 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 $ n $ lines contains two integers $ l_i $ and $ r_i $ ( $ 0 \le l_i < r_i \le a $ ) — the borders of the $ i $ -th segment under rain. It is guaranteed that there is no pair of intersecting segments. In other words, for each pair of segments $ i $ and $ j $ either $ r_i < l_j $ or $ r_j < l_i $ . Each of the next $ m $ lines contains two integers $ x_i $ and $ p_i $ ( $ 0 \le x_i \le a $ , $ 1 \le p_i \le 10^5 $ ) — the location and the weight of the $ i $ -th umbrella.
输出格式
Print "-1" (without quotes) if Polycarp can't make his way from point $ x = 0 $ to point $ x = a $ . Otherwise print one integer — the minimum total fatigue after reaching $ x = 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