A15885 | The Third Grace
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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$ .
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 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$ .
In the second sample, we will activate no points. The sum of costs of all intervals will be $0$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted