CodeForces - 344E Read Time (模拟题 + 二分法)
1 second
256 megabytes
standard input
standard output
Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read
data in parallel.
When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the i-th
reading head is above the track number hi.
For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads
can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the
tracks numbered h1, h2, ..., hn have
been read at the beginning of the operation.

Mike needs to read the data on m distinct tracks with numbers p1, p2, ..., pm.
Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.
The first line of the input contains two space-separated integers n, m (1 ≤ n, m ≤ 105)
— the number of disk heads and the number of tracks to read, accordingly. The second line contains n distinct integers hi in
ascending order (1 ≤ hi ≤ 1010, hi < hi + 1)
— the initial positions of the heads. The third line contains m distinct integers pi in
ascending order (1 ≤ pi ≤ 1010, pi < pi + 1)
- the numbers of tracks to read.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams
or the%I64d specifier.
Print a single number — the minimum time required, in seconds, to read all the needed tracks.
3 4
2 5 6
1 3 6 8
2
3 3
1 2 3
1 2 3
0
1 2
165
142 200
81
The first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way:
- during the first second move the 1-st head to the left and let it stay there;
- move the second head to the left twice;
- move the third head to the right twice (note that the 6-th track has already been read at the beginning).
One cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.
|
通过二分枚举时间,知道满足条件
#include <cstdio> |
CodeForces - 344E Read Time (模拟题 + 二分法)的更多相关文章
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 691C. Exponential notation 模拟题
C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
- CodeForces - 344B Simple Molecules (模拟题)
CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...
- CodeForces - 344D Alternating Current (模拟题)
id=46667" style="color:blue; text-decoration:none">CodeForces - 344D id=46667" ...
- CodeForces 681C Heap Operations (模拟题,优先队列)
题意:给定 n 个按顺序的命令,但是可能有的命令不全,让你补全所有的命令,并且要求让总数最少. 析:没什么好说的,直接用优先队列模拟就行,insert,直接放入就行了,removeMin,就得判断一下 ...
- CodeForces - 427B (模拟题)
Prison Transfer Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Codeforces Beta Round #7 B. Memory Manager 模拟题
B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
随机推荐
- 附001.kubectl介绍及使用
一 kubectl介绍 1.1 kubectl概要 kubectl控制Kubernetes集群管理器,使用Kubernetes命令行工具kubectl在Kubernetes上部署和管理应用程序.使用k ...
- muduo学习笔记(六) 多线程的TcpServer
目录 前言 多线程TcpServer EventLoopThreadPool 线程池设计模式 muduo中的使用 连接的建立.消息.销毁 on_connection on_message on_clo ...
- Git 基本命令行操作
一.本地仓库操作 1.初始化 git init 2.添加版本控制文件 git add README.md3.本地提交 git commit -m “1st commit”4.配置远程 ...
- Codeforces.1096E.The Top Scorer(组合)
题目链接 感觉这题很裸啊,除了看着恶心点也没什么了,怎么过的人那么少.. \(Description\) 给定\(n,r,s\),表示有\(n\)个人,设每个人的得分是非负整数\(a_i\),已知第一 ...
- VirtWire 注册教程
1 首先打开virtwire官方网站 网站地址:戳我 2 如果现实如下图所示,点击红色框中的网址连接.(网页中有Terms of Service可以读) 3 如果网页正常打开,点击“ORDERHOST ...
- [CC-BLREDSET]Black and Red vertices of Tree
[CC-BLREDSET]Black and Red vertices of Tree 题目大意: 有一棵\(n(\sum n\le10^6)\)个结点的树,每个结点有一种颜色(红色.黑色.白色).删 ...
- python系统编程(四)
进程池Pool 当需要创建的子进程数量不多时,可以直接利用multiprocessing中的Process动态成生多个进程,但如果是上百甚至上千个目标,手动的去创建进程的工作量巨大,此时就可以用到mu ...
- 学习 IOC 设计模式前必读:依赖注入的三种实现
一直以来就是越难的东西越值钱! 嘿嘿,这篇博文章转载自:http://www.cnblogs.com/liuhaorain/p/3747470.html 摘要 面向对象设计(OOD)有助于我们开发出高 ...
- helm-chart-1-简单概念介绍-仓库搭建-在rancher上的使用
简单的概念介绍: Chart是helm管理的应用的打包格式,一个chart对应一个或一套应用.内部是一系列的yaml描述文件,以为为yaml 服务的文件. 三个部分,helm .tiller.repo ...
- Helm: Error: no available release name found
如题,helm报这个错误 Helm: Error: no available release name found 错误的原因大概是因为 tiller没有正确的角色权限. 执行以下命令可解决这个问题. ...