CF822C.Hacker, pack your bags!
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You know the majority of people prefer to go somewhere for a vacation, so Leha immediately went to the travel agency. There he found out that n vouchers left. i-th voucher is characterized by three integers l__i, r__i, cost__i — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the i-th voucher is a value r__i - l__i + 1.
At the same time Leha wants to split his own vocation into two parts. Besides he wants to spend as little money as possible. Formally Leha wants to choose exactly two vouchers i and j (i ≠ j) so that they don't intersect, sum of their durations is exactly x and their total cost is as minimal as possible. Two vouchers i and j don't intersect if only at least one of the following conditions is fulfilled: r__i < l__j or r__j < l__i.
Help Leha to choose the necessary vouchers!
众所周知,摆脱某件事的最佳方式就是去做自己最喜欢的事。对莱哈(Leha)而言,编程工作(Job)正是这样一件事。
因此,这位黑客开始努力工作,以驱散无聊感——也就是说,莱哈开始在全球范围内黑入计算机。由于这种忘我的敬业精神,老板给了他整整 x 天的假期。众所周知,大多数人度假时都喜欢外出旅行,因此莱哈立刻前往了旅行社。在那里他得知,目前尚有 n 张旅游代金券(voucher)可供选择。第 i 张代金券由三个整数 li、ri、costi 表征:分别表示从维克波利斯(Vičkopolis)出发的日期、返回维克波利斯的日期,以及该代金券的费用。第 i 张代金券的持续时间为 ri−li+1。
与此同时,莱哈希望将自己的假期分为两段。此外,他还希望花费尽可能少的钱。形式化地说,莱哈需要恰好选择两张不同的代金券 i 和 j(即 i=j),使得它们互不重叠、它们的持续时间之和恰好为 x,且总费用最小。两张代金券 i 和 j 互不重叠,当且仅当满足以下两个条件之一:ri<lj 或 rj<li。
请帮助莱哈选出所需的两张代金券!
输入格式
The first line contains two integers n and x (2 ≤ n, x ≤ 2·105) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.
Each of the next n lines contains three integers l__i, r__i and cost__i (1 ≤ l__i ≤ r__i ≤ 2·105, 1 ≤ cost__i ≤ 109) — description of the voucher.
第一行包含两个整数 n 和 x(2 ≤ n, x ≤ 2⋅105)—— 分别表示旅行社中代金券的数量以及 Leha 的假期时长。
接下来的 n 行,每行包含三个整数 li、ri 和 costi(1 ≤ li ≤ ri ≤ 2⋅105,1 ≤ costi ≤ 109)—— 描述一张代金券。
输出格式
Print a single integer — a minimal amount of money that Leha will spend, or print - 1 if it's impossible to choose two disjoint vouchers with the total duration exactly x.
输出一个整数——Leha 需要花费的最少金额;如果无法选出两个不相交的代金券,使其总持续时间恰好为 x,则输出 −1。
输入输出样例
输入#1
4 5 1 3 4 1 2 5 5 6 1 1 2 4
输出#1
5
输入#2
3 2 4 6 3 2 4 1 3 5 4
输出#2
-1
说明/提示
In the first sample Leha should choose first and third vouchers. Hereupon the total duration will be equal to (3 - 1 + 1) + (6 - 5 + 1) = 5 and the total cost will be 4 + 1 = 5.
In the second sample the duration of each voucher is 3 therefore it's impossible to choose two vouchers with the total duration equal to 2.
在第一个样例中,Leha 应选择第一张和第三张代金券。此时总持续时间为 (3 − 1 + 1) + (6 − 5 + 1) = 5,总费用为 4 + 1 = 5。
在第二个样例中,每张代金券的持续时间均为 3,因此不可能选出两张总持续时间恰好为 2 的代金券。
输入解题思路,AI测评打分。不知道怎么写?