题意

给出一些闭区间(始末+代价),选取两段不重合区间使长度之和恰为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. react中如何实现一个按钮的动态隐藏和显示(有效和失效)

    初始准备工作 constructor(props) { super(props); /* * 构建导出数据的初始参数,结合用户下拉选择后动态设置参数值 * */ this.state = { btnS ...

  2. nmap探测大网络空间中的存活主机

    前言 扫描大网络空间中的存活主机 实现 nmap -v -sn -PE -n --min-hostgroup 1024 --min-parallelism 1024 -oX nmap_output.x ...

  3. Android Monkey压力测试(转)

    参考链接:https://www.cnblogs.com/yyh8/p/6707745.html Monkey 是Android SDK提供的一个命令行工具, 可以简单,方便地运行在任何版本的Andr ...

  4. python 全栈开发之旅

    目录 python 基础语法 python 数据类型(未完成) python 内置函数(未完成) python 常用标准库(未完成) python 类(未完成) python 进程.线程.协程(未完成 ...

  5. Windows Server 2012 R2蓝屏

    最近发现某个医院客户Windows Server 2012 R2 DataCenter的系统频繁蓝屏重启,重启没过一天再一次出现,反反复复折腾好几天,提示信息ntoskrnl.exe.mssmbios ...

  6. 处理人际关系的5大原则zz

    人际关系题是结构化面试当中重要的题型之一,人们常用两个“70%”来形容人际关系的重要性: 人际关系题主要考察考生不同人际关系间的适应性.人际合作的主动性.处理人际关系的原则性和灵活性以及对组织中权属关 ...

  7. LeetCode. 3的幂

    题目要求: 给定一个整数,写一个函数来判断它是否是 3 的幂次方. 示例: 输入: 27 输出: true 代码: class Solution { public: bool isPowerOfThr ...

  8. Appium移动端自动化测试--元素操作与触摸动作

    常见自动化动作支持 click sendKeys swipe touch action 元素操作 1.click()点击操作 也可以用tab实现点击操作 driver.find_element_by_ ...

  9. java实现带过期时间的缓存

    private static ScheduledExecutorService swapExpiredPool = new ScheduledThreadPoolExecutor(10); priva ...

  10. asp.net MVC 抓取微信文章数据(正文)

    1.抓微信的正文主要是调用第三方的接口(https://market.aliyun.com/products/56928004/cmapi012134.html) using Newtonsoft.J ...