CF822C.Hacker, pack your bags!

普及/提高-

通过率:0%

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 xx 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 nn vouchers left. ii -th voucher is characterized by three integers lil_{i} , rir_{i} , costicost_{i} — day of departure from Vičkopolis, day of arriving back in Vičkopolis and cost of the voucher correspondingly. The duration of the ii -th voucher is a value rili+1r_{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 ii and jj (ij)(i≠j) so that they don't intersect, sum of their durations is exactly xx and their total cost is as minimal as possible. Two vouchers ii and jj 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!

输入格式

The first line contains two integers nn and xx (2<=n,x<=2105)(2<=n,x<=2·10^{5}) — the number of vouchers in the travel agency and the duration of Leha's vacation correspondingly.

Each of the next nn lines contains three integers lil_{i} , rir_{i} and costicost_{i} (1<=li<=ri<=2105,1<=costi<=109)(1<=l_{i}<=r_{i}<=2·10^{5},1<=cost_{i}<=10^{9}) — description of the voucher.

输出格式

Print a single integer — a minimal amount of money that Leha will spend, or print 1-1 if it's impossible to choose two disjoint vouchers with the total duration exactly xx .

输入输出样例

  • 输入#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 (31+1)+(65+1)=5(3-1+1)+(6-5+1)=5 and the total cost will be 4+1=54+1=5 .

In the second sample the duration of each voucher is 33 therefore it's impossible to choose two vouchers with the total duration equal to 22 .

首页