题意

给出一些闭区间(始末+代价),选取两段不重合区间使长度之和恰为x且代价最低

思路

相同持续时间的放在一个vector中,内部再对起始时间排序,从后向前扫获取对应起始时间的最优代价,存在minn中,对时间 i 从前向后扫,在对应的k-i中二分找第一个不重合的区间,其对应的minn加上 i 的cost即为出发时间为 i 时的最优解

代码

#include<bits/stdc++.h>
using namespace std;
int n, k;
struct EVE{
int st,ed,val;
EVE(){
}
EVE(int a,int b, int c){
st = a, ed = b, val = c;
}
};
int f,t,c;
vector<EVE> v[];
vector<int> minn[];
int tmp[];
bool cmp(EVE a, EVE b){
return a.st<b.st;
}
int main(){
scanf("%d%d",&n,&k);
for(int i = ;i<n;i++){
scanf("%d%d%d",&f,&t,&c);
if(t-f+ >= k) continue;
v[t-f+].push_back({f,t,c});
}
for(int i = ;i<=k;i++) sort(v[i].begin(),v[i].end(),cmp);
for(int i = ;i<=k;i++){
for(int j = v[i].size()-;j>=;j--){
if(j==v[i].size()-) tmp[j]=v[i][j].val;
else tmp[j]=min(v[i][j].val,tmp[j+]);
}
for(int j = ;j<v[i].size();j++){
minn[i].push_back(tmp[j]);
}
}
long long ans = 1e12;
for(int i = ;i<=k;i++){
if(v[k-i].empty()) continue;
for(int j = ;j<v[i].size();j++){
int ed = v[i][j].ed;
long long cost = v[i][j].val;
int le = , ri = v[k-i].size()-;
if(v[k-i][ri].st<=ed) continue;
int mid = le+ri>>;
while(le<ri){
mid = le+ri>>;
if(v[k-i][mid].st<=ed) le = mid+;
else ri = mid;
}
ans = min(ans, cost+minn[k-i][le]);
}
}
if(ans == 1e12) printf("-1");
else printf("%I64d",ans);
return ;
}

CodeForces 822C Hacker, pack your bags!的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

  9. codeforces 822 C. Hacker, pack your bags!(思维+dp)

    题目链接:http://codeforces.com/contest/822/submission/28248100 题解:多维的可以先降一下维度sort一下可以而且这种区间类型的可以拆一下区间只要加 ...

随机推荐

  1. Java环境中,word文档转PDF直接打开浏览而非下载

    在平台上,需要把文档直接浏览而非下载,实现方法是先把文档转为PDF文件, 但在linux系统中确实汉字字库,所以转换失败,以下是解决方法 后面正式服务器也要添加字库,不然会转换出乱码文件,处理步骤如下 ...

  2. FastCGI模式编译安装LAMP+Xcache

    PHP的工作模式:php在lamp环境下共有三种工作模式:CGI模式.apache模块.FastCGI模式.CGI模式下运行PHP,性能不是很好.(已淘汰)FastCGI的方式和apache模块的不同 ...

  3. Release报错Debug无错

    代码在Release模式下会crash,Debug模式下可以运行,最后定位到原因 for (size_t j = 0; j < ids.size()-1; ++j) { } 发现问题是Relea ...

  4. shuffle 打乱一维数组

    <?php $arr = range(,); print_r($arr); echo '<br />'; shuffle($arr); print_r($arr); ?> Ar ...

  5. Win10使用mysqldump导出csv文件及期间遇到的问题

    作为测试,我们这里使用了名为testdb的数据库中的名为test_table的表,首先我们使用如下SQL来查看其中有何数据: select * from testdb.test_table 数据如下: ...

  6. 【Leetcode_easy】1089. Duplicate Zeros

    problem 1089. Duplicate Zeros 题意: solution: 其中关于虚拟新数组的下标的计算还是有点迷糊... class Solution { public: void d ...

  7. python:python2与python3共存时,pip冲突,提示Fatal error in launcher: Unable to create process using '"d:\python27\python2.exe" "D:\Python27\Scripts\pip2.exe" '

    问题背景: 机器上同时装了python2.和python3后,导致只能用pip3了,使用pip2时提示:Fatal error in launcher: Unable to create proces ...

  8. Python中logging在多进程环境下打印日志

    因为涉及到进程间互斥与通信问题,因此默认情况下Python中的logging无法在多进程环境下打印日志.但是查询了官方文档可以发现,推荐了一种利用logging.SocketHandler的方案来实现 ...

  9. 学习笔记:oracle学习一:oracle11g体系结构之体系结构概述和逻辑存储结构

    目录 1.oracle 11g体系结构概述 1.1 三个重要概念 1.2 oracle数据库存储结构 2 逻辑存储结构 2.1 数据块(Data Blocks) 2.2 数据区(Extent) 2.3 ...

  10. 日常工作问题解决:redhat6.9--解决yum功能不能正常使用和配置yum源

    1.问题描述 解决RedHat6.9下yum功能不能用问题: 在redhat6.9下使用yum安装时,会提示:This system is not registered to Red Hat Subs ...