Codeforces Round 875 (Div. 1)
F
The Third Grace
Codeforces
3200
原题
← E→
翻译中…

You are given $n$ intervals and $m$ points on the number line. The $i$-th intervals covers coordinates $[l_i,r_i]$ and the $i$-th point is on coordinate $i$ and has coefficient $p_i$.

翻译中…

Initially, all points are not activated. You should choose a subset of the $m$ points to activate. For each of $n$ interval, we define its cost as:

翻译中…
  • $0$, if there are no activated points in the interval;
  • the coefficient of the activated point with the largest coordinate within it, otherwise.
翻译中…

Your task is to maximize the sum of the costs of all intervals by choosing which points to activate.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 10^5$) — the number of test cases. The description of test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \le n \le 10^6, 1 \le m \le 10^6$) — the number of intervals and the number of points.

翻译中…

The following $n$ lines of each test case contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le m$) — the endpoints of the $i$-th interval.

翻译中…

The following line of each test case contains $m$ integers $p_1,p_2,\ldots,p_m$ ($0 \le p_i \le 10^9$) — the coefficients of the points.

翻译中…

It is guaranteed that the sum of $n$ does not exceed $10^6$ and the sum of $m$ does not exceed $10^6$.

翻译中…

Output

翻译中…

Output the maximum possible sum of costs of all intervals.

翻译中…

Note

翻译中…

In the first sample, we can activate points $1$ and $8$. The sum of costs of all intervals will be $78+30=108$.

翻译中…

In the second sample, we will activate no points. The sum of costs of all intervals will be $0$.

翻译中…

样例

Input #1
2
2 8
1 5
3 8
78 0 50 0 0 0 0 30
1 6
1 5
0 0 0 0 0 100
Output #1
108
0
InputCopy OutputCopy
题目信息
题号
1830F
时间限制
5 s
内存限制
1024 MB
标签
数据结构
动态规划

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