A14387 | Boring Segments
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given $n$ segments on a number line, numbered from $1$ to $n$ . The $i$ -th segments covers all integer points from $l_i$ to $r_i$ and has a value $w_i$ .
You are asked to select a subset of these segments (possibly, all of them). Once the subset is selected, it's possible to travel between two integer points if there exists a selected segment that covers both of them. A subset is good if it's possible to reach point $m$ starting from point $1$ in arbitrary number of moves.
The cost of the subset is the difference between the maximum and the minimum values of segments in it. Find the minimum cost of a good subset.
In every test there exists at least one good subset.
You are asked to select a subset of these segments (possibly, all of them). Once the subset is selected, it's possible to travel between two integer points if there exists a selected segment that covers both of them. A subset is good if it's possible to reach point $m$ starting from point $1$ in arbitrary number of moves.
The cost of the subset is the difference between the maximum and the minimum values of segments in it. Find the minimum cost of a good subset.
In every test there exists at least one good subset.
输入格式
The first line contains two integers $n$ and $m$ ( $1 \le n \le 3 \cdot 10^5$ ; $2 \le m \le 10^6$ ) — the number of segments and the number of integer points.
Each of the next $n$ lines contains three integers $l_i$ , $r_i$ and $w_i$ ( $1 \le l_i < r_i \le m$ ; $1 \le w_i \le 10^6$ ) — the description of the $i$ -th segment.
In every test there exists at least one good subset.
Each of the next $n$ lines contains three integers $l_i$ , $r_i$ and $w_i$ ( $1 \le l_i < r_i \le m$ ; $1 \le w_i \le 10^6$ ) — the description of the $i$ -th segment.
In every test there exists at least one good subset.
输出格式
Print a single integer — the minimum cost of a good subset.
输入输出样例
输入 #1
5 12 1 5 5 3 4 10 4 10 6 11 12 5 10 12 3
输出 #1
3
输入 #2
1 10 1 10 23
输出 #2
0
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted