CF1830F.The Third Grace
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n intervals and m points on the number line. The i-th intervals covers coordinates [li,ri] and the i-th point is on coordinate i and has coefficient pi.
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.
给你数轴上的 n 个区间和 m 个点。第 i 个区间覆盖坐标范围 [li,ri],第 i 个点位于坐标 i 处,其系数为 pi。
初始时,所有点均未被激活。你需要从这 m 个点中选择一个子集进行激活。对每个区间(共 n 个),我们定义其代价如下:
- 若该区间内没有被激活的点,则代价为 0;
- 否则,代价为该区间内所有被激活点中坐标最大的那个点的系数。
你的任务是通过选择合适的点进行激活,使得所有区间的代价之和最大。
输入格式
Each test contains multiple test cases. The first line of input contains a single integer t (1≤t≤105) — 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≤n≤106,1≤m≤106) — the number of intervals and the number of points.
The following n lines of each test case contains two integers li and ri (1≤li≤ri≤m) — the endpoints of the i-th interval.
The following line of each test case contains m integers p1,p2,…,pm (0≤pi≤109) — the coefficients of the points.
It is guaranteed that the sum of n does not exceed 106 and the sum of m does not exceed 106.
每个测试包含多个测试用例。输入的第一行包含一个整数 t(1≤t≤105),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n≤106, 1≤m≤106),分别表示区间的数量和点的数量。
每个测试用例的接下来 n 行,每行包含两个整数 li 和 ri(1≤li≤ri≤m),表示第 i 个区间的左右端点。
每个测试用例的下一行包含 m 个整数 p1,p2,…,pm(0≤pi≤109),表示各点的系数。
保证所有测试用例中 n 的总和不超过 106,且所有测试用例中 m 的总和不超过 106。
输出格式
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 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.
在第一个样例中,我们可以激活点 1 和 8。所有区间的成本之和为 78+30=108。
在第二个样例中,我们将不激活任何点。所有区间的成本之和为 0。
输入解题思路,AI测评打分。不知道怎么写?