博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codefroces 822C Hacker, pack your bags!
阅读量:5165 次
发布时间:2019-06-13

本文共 2805 字,大约阅读时间需要 9 分钟。

C. Hacker, pack your bags!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 li, ri, costi — 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 ri - li + 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: ri < lj or rj < li.

Help Leha to choose the necessary vouchers!

Input

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 li, ri and costi(1 ≤ li ≤ ri ≤ 2·105, 1 ≤ costi ≤ 109) — description of the voucher.

Output

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.

Examples
Input
4 5 1 3 4 1 2 5 5 6 1 1 2 4
Output
5
Input
3 2 4 6 3 2 4 1 3 5 4
Output
-1
Note

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.

容器解题

#include 
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;#define lowbit(x) x&(-x)#define max(x,y) (x>y?x:y)#define min(x,y) (x
>v[200006];int main(){ int l,r,c,n,x; ll minn=inf; cin>>n>>x; for(int i=0;i
x) continue; v[r-l+1].push_back(make_pair(l,c)); } for(int i=0;i<=x;i++)sort(v[i].begin(),v[i].end()); for(int d=1;d

 

转载于:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7153986.html

你可能感兴趣的文章
移动开发在路上-- IOS移动开发系列 多线程三
查看>>
CNPM
查看>>
IOS-SQLite3
查看>>
Masonry代码自动布局的简单使用。
查看>>
spring 公用异常处理
查看>>
《思帝乡·春日游》——[唐]韦庄
查看>>
poj 2391 Ombrophobic Bovines【最大流】
查看>>
有关C++新特性
查看>>
队列 二
查看>>
jQuery选择器
查看>>
uva2965
查看>>
Window下增加/取消开机启动项的方式(修改注册表)
查看>>
实验一 查看CPU和内存,用机器指令和汇编指令编程
查看>>
使用C语言判断一个IP 地址是否为私有地址
查看>>
springboot整合xxl-mq学习笔记
查看>>
面试系列17 redis cluster
查看>>
MyEclipse的 at com.genuitec.eclipse.ast.deploy.core.Deployment.<init>错误解决办法
查看>>
POJ 2251 Dungeon Master(3D迷宫 bfs)
查看>>
Linux查看和编辑文件
查看>>
MVC之 自定义过滤器(Filter)
查看>>