CF1555E.Boring Segments
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n segments on a number line, numbered from 1 to n . The i -th segments covers all integer points from li to ri and has a value wi .
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≤n≤3⋅105 ; 2≤m≤106 ) — the number of segments and the number of integer points.
Each of the next n lines contains three integers li , ri and wi ( 1≤li<ri≤m ; 1≤wi≤106 ) — 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