【Codeforces 1148B】Born This Way
【链接】 我是链接,点我呀:)
【题意】
有人要从A地飞向B地,然后从B地飞向C地。
给出A,B地的n、m个航班的出发时间。
已知从A到B的航班都是ta和tb时长到达B、C
只有到达B的时候航班还没起飞才能乘坐(当然也可以等下一班)
问你现在你可以去掉最多K个航班,这个人到达C地最晚的时间是啥时候(那个人会在你删掉之后选择最好的方案)(或者直接输出这个人不能到达C)
【题解】
如果你是那个人肯定知道从A出发的航班肯定越早越好。
最后的K个航班肯定是从A、B两地的航班里删掉的。
所以我们可以这样,枚举删掉了A的多少个航班i(显然是删掉最早的i个航班效果最佳)
然后看看最早的航班是啥时候到B即为a[i+1]+ta
显然我们要找到最小的大于等于a[i+1]+ta的b[idx].
但是不着急 我们可以接着删除k-i个航班,则也是同样的策略
删idx接下来的k-i个即可。从而得到A航班删掉i个的情况下总共删掉k个这个人最早到达C的时间了。
在所有的可能中取最大值就好了。
注意-1的几种情况就好了
【代码】
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cstring>
using namespace std;
const int N = 2e5;
int n,m,ta,tb,k;
int a[N+10],b[N+10];
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m >> ta >> tb >> k;
for (int i = 1;i <= n;i++) cin >> a[i];
for (int i = 1;i <= m;i++) cin >> b[i];
if (k>=n){
cout<<-1<<endl;
return 0;
}
int ans = 0;
for (int i = 1;i <= min(k+1,n);i++){
int used1 = i-1;
int idx2 = lower_bound(b+1,b+1+m,a[i]+ta)-b;
if (idx2>m){
cout<<-1<<endl;
return 0;
}
int rest = k-used1;
if (idx2+rest>m){
cout<<-1<<endl;
return 0;
}
idx2 = idx2+rest;
ans = max(ans,b[idx2]+tb);
}
cout<<ans<<endl;
return 0;
}
【Codeforces 1148B】Born This Way的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- java多线程面试题_线程并发面试题
1.什么是线程?线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务提速.比如,如果一个线程完成一个 ...
- 在Eclipse上安装Spring Tool Suite
. 不装IDE会没有Spring bean configure file Spring Tool Suite是一个基于Eclipse IDE开发环境中的用于开发Spring应用程序的工具,提供了开箱即 ...
- Python Class (一)
继承 class Character(object): def __init__(self, name): self.health = 100 self.name = name def printNa ...
- Java中的Set集合以及HashSet
Set集合: Set继承自Collection,所以没有什么特别的方法. 需要注意的是,Set集合不包含重复元素,我们重点了解Set集合如何保证不包含多余元素. HashSet: HashSet如何保 ...
- HTML5 worker计数器简单示例
效果图: index.html var w; // 开始 function startWorker() { if (typeof (Worker) !== "undefined") ...
- 【leetcode】133. Clone Graph
题目如下: Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph con ...
- MySQL - primary key PK unique key,key PK index
primary key PK unique key 总结 primary key = unique + not null 主键不能为空每个字段值都不重复,unique可以为空,非空字段不重复 uniq ...
- HDU 4279 Number 坑爹的迷之精度
题目描述 首先定义"special number": 如果对于一个数字B,存在一个数字A(0<A<=B),并同时满足 B%A=0 和 gcd(A,B) != 1 ,那么 ...
- (转)MySQL安装及配置指南
转:http://wiki.ubuntu.org.cn/MySQL%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97 安装MySQL sudo apt-get install m ...
- python 读取设备的另一个方法
import time,sys templist = []#设置一个空列表,用来放设备内容deviceslist =[]#设置一个空列表,用来放分割后的设备内容devices = [] #设置一 ...