CF1555E.Boring Segments

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn segments on a number line, numbered from 11 to nn. The ii-th segments covers all integer points from lil_i to rir_i and has a value wiw_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 mm starting from point 11 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.

给你数轴上的 nn 条线段,编号从 11 到 nn。第 ii 条线段覆盖所有从 lil_i 到 rir_i 的整数点,并具有权值 wiw_i。

你需要从中选出一个子集(可以包含全部线段)。选定子集后,若存在一条被选中的线段同时覆盖两个整数点,则可以从其中一个点移动到另一个点。若能从点 11 出发,经过任意次移动到达点 mm,则称该子集是“好的”。

该子集的代价定义为其中所含线段权值的最大值与最小值之差。请找出一个“好”子集的最小可能代价。

每个测试用例中至少存在一个“好”子集。

输入格式

The first line contains two integers nn and mm (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5; 2≤m≤1062 \le m \le 10^6) — the number of segments and the number of integer points.

Each of the next nn lines contains three integers lil_i, rir_i and wiw_i (1≤li<ri≤m1 \le l_i \lt r_i \le m; 1≤wi≤1061 \le w_i \le 10^6) — the description of the ii-th segment.

In every test there exists at least one good subset.

第一行包含两个整数 nn 和 mm(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5;2≤m≤1062 \le m \le 10^6)—— 分别表示线段的数量和整数点的数量。

接下来的 nn 行中,每行包含三个整数 lil_i、rir_i 和 wiw_i(1≤li<ri≤m1 \le l_i \lt r_i \le m;1≤wi≤1061 \le w_i \le 10^6)—— 描述第 ii 条线段。

在每个测试用例中,至少存在一个“好”的子集。

输出格式

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

输入解题思路,AI测评打分。不知道怎么写?

首页