思路:

对于一个区间[l, r],只需枚举所有满足r' < l并且二者duration之和为x的区间[l', r'],寻找其中二者cost之和最小的即可。于是可以开一个数组a[],a[i]表示所有能与i配对的区间(duration为x - i)的最小花费。计算的时候根据区间左端点由小到大依次更新就可以满足区间不重叠的限制,具体参见代码。

实现:

 #include <iostream>
#include <cstdio>
#include <vector>
using namespace std; typedef long long ll;
const ll MAXN = , INF = 0x3f3f3f3f3f3f3f3f;
typedef pair<ll, ll> P;
vector<P> L[MAXN], R[MAXN];
ll a[MAXN]; int main()
{
ll n, x, l, r, c;
scanf("%I64d %I64d", &n, &x);
fill(a, a + MAXN, INF);
for (int i = ; i < n; i++)
{
scanf("%I64d %I64d %I64d", &l, &r, &c);
L[l].push_back({r - l + , c});
R[r].push_back({r - l + , c});
}
ll ans = INF;
for (int i = ; i < MAXN; i++)
{
for (auto it : L[i])
{
if (it.first >= x) continue;
ans = min(ans, a[x - it.first] + it.second);
}
for (auto it : R[i])
a[it.first] = min(a[it.first], it.second);
}
cout << (ans == INF ? - : ans) << endl;
return ;
}

CF822C Hacker, pack your bags!的更多相关文章

  1. CF822C Hacker, pack your bags!(思维)

    Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...

  2. CF-822C Hacker, pack your bags! 思维题

    题目大意是给若干线段及其费用,每个线段权值即为其长度.要求找出两个不重合线段,令其权值和等于x且费用最少. 解法: 先分析一下题目,要处理不重合的问题,有重合的线段不能组合,其次这是一个选二问题,当枚 ...

  3. Codeforces822 C. Hacker, pack your bags!

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

  4. Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序,贪心

    C. Hacker, pack your bags!     It's well known that the best way to distract from something is to do ...

  5. CodeForces 754D Fedor and coupons&&CodeForces 822C Hacker, pack your bags!

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  6. Codefroces 822C Hacker, pack your bags!

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

  7. Codeforces 822C Hacker, pack your bags! - 贪心

    It's well known that the best way to distract from something is to do one's favourite thing. Job is ...

  8. Codeforces 822C Hacker, pack your bags!(思维)

    题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...

  9. Codeforces Round #422 (Div. 2) C. Hacker, pack your bags!(更新数组)

    传送门 题意 给出n个区间[l,r]及花费\(cost_i\),找两个区间满足 1.区间和为指定值x 2.花费最小 分析 先用vector记录(l,r,cost)和(r,l,cost),按l排序,再设 ...

随机推荐

  1. Ubuntu 16.04安装TortoiseSVN(基于CrossOver)

    基于CrossOver的TortoiseSVN有如下缺点: 1.不能像Windows下实现右键菜单提交,但是可以通过TortoiseSVN实现迁出代码. 可以解决的问题: 1.可以通过Tortoise ...

  2. MYSQL 时间数据类型

  3. 表单验证的完美解决方案Validform

    具体使用方法参考官网介绍吧,相当的简单: 文档:http://validform.rjboy.cn/document.html demo:http://validform.rjboy.cn/demo. ...

  4. Linux命令输出头(标题)、输出结果排序技巧

    原文:http://blog.csdn.net/hongweigg/article/details/65446007 ----------------------------------------- ...

  5. FlashBuilder 4.7 非正常关闭导致的不能启动的解决的方法

    停电.或者卡死.FB就不能正常启动了. 以下是老外给出的方法,好用: 进入.metadata/.plugins/org.eclipse.core.resources 文件夹 删除.snap文件 假设是 ...

  6. Skype for Business七大新功能

    Lync Server 2013的下一版本号.Skype for Business将于2015年4月正式公布,下面是七大新功能. "呼叫监听"(Call Monitor)--假设你 ...

  7. c#如何设置成:【当前打开的项目是什么,就默认它为启动项目】,不然新添或打开别的项目都要设置一次启动 [原创]VS2012中将当前选定项目做为启动项

    主菜单→[工具]→[选项]→[项目和解决方案]→[生成并运行],选中“对于新解决方案,使用当前选定的项目作为启动项目” 应该是右键单击解决方案,点击属性打开,选中“当前选定内容”那一项,就可以把你正在 ...

  8. [LeetCode][Java] Jump Game II

    题目: Given an array of non-negative integers, you are initially positioned at the first index of the ...

  9. Python开发【第*篇】【模块】

    模块分为三种: 自定义模块 第三方模块 内置模块 1.模块导入 import model from model.xx.xx import xx from model.xx.xx import xx a ...

  10. Go 语言的下一个大版本:Go 2.0 被安排上了(全面兼容1.X,改进错误处理和泛型这两大主题)

    今年 8 月 Go 开发团队公布了 Go 2.0 的设计草案,包括错误处理和泛型这两大主题.现在备受瞩目的 Go 2.0 又有了新动向 —— 昨日 Go 开发团队在其官方博客表示,Go 2 已经被安排 ...