CodeForces 822C Hacker, pack your bags!
题意
给出一些闭区间(始末+代价),选取两段不重合区间使长度之和恰为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!的更多相关文章
- 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 ...
- 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 ...
- Codeforces 822C Hacker, pack your bags!(思维)
题目大意:给你n个旅券,上面有开始时间l,结束时间r,和花费cost,要求选择两张时间不相交的旅券时间长度相加为x,且要求花费最少. 解题思路:看了大佬的才会写!其实和之前Codeforces 776 ...
- 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 ...
- 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 ...
- CF822C Hacker, pack your bags!(思维)
Hacker, pack your bags [题目链接]Hacker, pack your bags &题意: 有n条线段(n<=2e5) 每条线段有左端点li,右端点ri,价值cos ...
- 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 ...
- 【Codeforces Round #422 (Div. 2) C】Hacker, pack your bags!(二分写法)
[题目链接]:http://codeforces.com/contest/822/problem/C [题意] 有n个旅行计划, 每个旅行计划以开始日期li,结束日期ri,以及花费金钱costi描述; ...
- codeforces 822 C. Hacker, pack your bags!(思维+dp)
题目链接:http://codeforces.com/contest/822/submission/28248100 题解:多维的可以先降一下维度sort一下可以而且这种区间类型的可以拆一下区间只要加 ...
随机推荐
- nginx conf 文件
server { listen ; server_name local.light.com; index index.html index.htm index.php; root /home/wwwr ...
- 【ARTS】01_34_左耳听风-201900701~201900707
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- Spring 使用单选按钮
模型层需要提供数据选项,设置错误信息 关键代码 @NotNull(message = "请选择性别") private String gender; 控制器层需要在显示视图前,通过 ...
- php5.6安装及php-fpm优化配置
1,安装依赖包: yum install -y gcc gcc-c++ zlib zlib-devel pcre pcre-devel gd libjpeg libjpeg-devel libpn ...
- Navicat 导入,导出数据 etc
Navicat 不仅做了分页查询, 显示 `SELECT *,rowid "NAVICAT_ROWID" FROM "main"."Table_100 ...
- HTTP最常见的响应头
HTTP最常见的响应头如下所示: l Allow:服务器支持哪些请求方法(如GET.POST等): l Content-Encoding:文档的编码(Encode)方法 ...
- Idea生成的的第一个eureka注册中心服务器
操作: 1.file->new->project Spring Initializer ->default 点击next 2.输入 Group ...
- python Django基础操作
Django常用命令 创建Django项目 Django-admin startprotect mysite 创建项目以后,以下生成的文件 最外层的file:mysite/ 根目录只是你的项目的容器 ...
- 1261: 单位转换(Java)
WUSTOJ 1261: 单位转换 参考资料 数字字符串拆分--百度知道 Description BobLee最近在复习考研,在复习计算机组成原理的时候,遇到了一个问题.就是在计算机存储里面的单位转换 ...
- Codefroces 1245 F. Daniel and Spring Cleaning
传送门 考虑简单的容斥 设 $F(n,m)$ 表示 $a \in [1,n] , b \in [1,m]$ 的满足 $a+b=a \text{ xor } b$ 的数对的数量 那么答案即为 $F(r, ...