接上一篇文章;

这里直接把左端点和右端点映射到vector数组上;

映射一个open和close数组;

枚举1..2e5

如果open[i]内有安排;

则用那个安排和dp数组来更新答案;

更新答案完之后,如果有close数组

则把close数组里面的安排用来更新dp数组;

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2e5;
const int INF = 2e9+10; struct abc{
int l,r,cost;
}; int n,x,dp[N],ans = INF;
vector <abc> open[N+100],close[N+100]; int main(){
//Open();
Close();
cin >> n >> x;
abc temp;
rep1(i,1,n){
cin >> temp.l >> temp.r >> temp.cost;
open[temp.l].pb(temp);
close[temp.r].pb(temp);
}
int len;
rep1(i,1,N){
while (!open[i].empty()){
temp = open[i].back();
open[i].pop_back();
len = temp.r-temp.l+1;
if (x>=len){
if (dp[x-len] > 0)
ans = min(ans,dp[x-len]+temp.cost);
}
}
while (!close[i].empty()){
temp = close[i].back();
close[i].pop_back();
len = temp.r-temp.l+1;
if (dp[len]==0)
dp[len] = temp.cost;
else
dp[len] = min(dp[len],temp.cost);
}
}
if (ans==INF)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}

【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(hash写法)的更多相关文章

  1. 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 ...

  2. 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排序,再设 ...

  3. Codeforces Round #422 (Div. 2)

    Codeforces Round #422 (Div. 2) Table of Contents Codeforces Round #422 (Div. 2)Problem A. I'm bored ...

  4. 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)

    [题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...

  5. Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP

    E. Liar     The first semester ended. You know, after the end of the first semester the holidays beg ...

  6. Codeforces Round #422 (Div. 2) B. Crossword solving 枚举

    B. Crossword solving     Erelong Leha was bored by calculating of the greatest common divisor of two ...

  7. Codeforces Round #422 (Div. 2) A. I'm bored with life 暴力

    A. I'm bored with life     Holidays have finished. Thanks to the help of the hacker Leha, Noora mana ...

  8. 【Codeforces Round #422 (Div. 2) D】My pretty girl Noora

    [题目链接]:http://codeforces.com/contest/822/problem/D [题意] 有n个人参加选美比赛; 要求把这n个人分成若干个相同大小的组; 每个组内的人数是相同的; ...

  9. 【Codeforces Round #422 (Div. 2) B】Crossword solving

    [题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...

随机推荐

  1. RGB与16进制色互转

      点击进入新版 <前端在线工具站> CSS, JavaScript 压缩YUI compressor, JSPacker...HTML特殊符号对照表PNG,GIF,JPG... Base ...

  2. JavaScript学习——使用JS完成全选和全不选操作

    1.我们希望在后台系统实现一个批量删除的操作(全选所有的复选框)和全不选,显示效果如下: 2.步骤分析: 第一步:确定事件(onclick)并为其绑定一个函数(事件绑定到编号前面的复选框里面) 第二步 ...

  3. 通过curl获取网页访问时间

    curl -w %{time_namelookup}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download}&quo ...

  4. 关于RoI pooling 层

    ROIs Pooling顾名思义,是pooling层的一种,而且是针对ROIs的pooling: 整个 ROI 的过程,就是将这些 proposal 抠出来的过程,得到大小统一的 feature ma ...

  5. confluence6.0.3安装文档

    一.Atlassian Confluence 6.0.3安装文档包含内容 1.wiki的安装步骤: 2.旧系统迁移中碰到的无法编辑和问题和解决方案: 3.wiki源码安装包.连接mysql用的jar包 ...

  6. 算法38---292. Nim游戏

    1.题目: 你和你的朋友,两个人一起玩 Nim游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解. 编写一个函 ...

  7. [六省联考2017]分手是祝愿(期望+DP)

    题解 很容易想出来最优策略是什么. 就是从n到1看到开着的灯就把它关了 我们预处理出当前状态把灯全部关闭后的最少步数cnt 然后我们的主人公就要瞎按... 设dp[i]代表当前状态最优解为i步时走到d ...

  8. centos7 jumpserver 部署和使用手册(二)

    前面已经介绍了jumpserver的部署,基于这篇部署文档,下面介绍下部署完成后的的功能使用: 一.系统设置 1.1根据提供的帐号密码(admin/admin)登录jumpserver 修改 url ...

  9. Vue异步组件Demo

    Vue异步组件Demo 在大型应用中,我们可能需要将应用拆分为多个小模块,按需从服务器下载.为了进一步简化,Vue.js 允许将组件定义为一个工厂函数,异步地解析组件的定义.Vue.js 只在组件需要 ...

  10. Object-C,对象和方法

    学习Object-C,买了2本书,其中1本是用C币买的,总体质量一般,比较基础. 另外一本是,疯狂-李阳写的,大部头,比较吓人,比较全一点. 对于面向对象,之前还是有个大概的理解,再多点基础的例子. ...