CF1830F.The Third Grace

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given nn intervals and mm points on the number line. The ii -th intervals covers coordinates [li,ri][l_i,r_i] and the ii -th point is on coordinate ii and has coefficient pip_i .

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

  • 00 , 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.

输入格式

Each test contains multiple test cases. The first line of input contains a single integer tt ( 1t1051 \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 nn and mm ( 1n106,1m1061 \le n \le 10^6, 1 \le m \le 10^6 ) — the number of intervals and the number of points.

The following nn lines of each test case contains two integers lil_i and rir_i ( 1lirim1 \le l_i \le r_i \le m ) — the endpoints of the ii -th interval.

The following line of each test case contains mm integers p1,p2,,pmp_1,p_2,\ldots,p_m ( 0pi1090 \le p_i \le 10^9 ) — the coefficients of the points.

It is guaranteed that the sum of nn does not exceed 10610^6 and the sum of mm does not exceed 10610^6 .

输出格式

Output the maximum possible sum of costs of all intervals.

输入输出样例

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

    输出#1

    108
    0

说明/提示

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

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

首页