接上一篇文章;

这里直接把左端点和右端点映射到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. jquery.gritter 提示

    首先引入css和js文件 <link rel="stylesheet" href="<%=basePath%>assets/css/jquery.gri ...

  2. shell基础编程

    首先要注意的是,Ubuntu里的shell的sh和bash命令是有区别的 如下所示,Ubuntu下的sh指向的dash程序,而bash是dash的增强版,一些bash上能执行的程序在dash上不行 如 ...

  3. AJAX和JSON笔记

    ### 1. 响应正文  传统的处理请求时,响应的方式有转发或重定向,无论是哪种,最终都会直接呈现某个页面给客户端,这样做的缺点在于:  1. 用户体验可能不好,例如:用户注册时,提交的用户名被占用, ...

  4. [HNOI2008]越狱 快速幂 逆推

    考虑越狱的情况有些复杂,不如考虑总情况减去不越狱的情况. 显然,总情况为 $m^n$ 种,不越狱的情况为 $m*(m-1)*(m-1)*(m-1)....$ 即为 $m*(m-1)^(n-1)$. 做 ...

  5. jQuery 完整 ajax示例

    $(function(){ //请求参数 var list = {}; // $.ajax({ //请求方式 type : "POST", //请求的媒体类型 contentTyp ...

  6. 基于 Token 的身份验证:JSON Web Token

    最近了解下基于 Token 的身份验证,跟大伙分享下.很多大型网站也都在用,比如 Facebook,Twitter,Google+,Github 等等,比起传统的身份验证方法,Token 扩展性更强, ...

  7. S-T表学习笔记

    $O(nlogn)$构造$O(1)$查询真是太强辣 然而不支持修改= = ShØut! #include<iostream> #include<cstring> #includ ...

  8. javaweb集成swagger

    一.添加依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-sw ...

  9. ip iproute2的典型应用

    net-tools和iproute2的命令做对比,做到简单明了,分别演示如何去获取.配置和操作系统网络信息. 以下是net-tools和iproute2的大致对比: 4.1 ip link set-- ...

  10. Python学习————集合的增删查

    可变的数据类型,他里面的元素必须是不可变的数据类型.无序,内容不能重复.应用于去重 增加:set1.add('元素')--->将元素无序的插入集合set1中set1.update("元 ...