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 ...
随机推荐
- 无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换
无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换 前言: Maya 集成了 PySide,同时集成了qt designer,在 Maya 的安装目录下的 bin ...
- datetime.timedelta类
datetime.timedelta对象代表两个时间之间的时间差,两个date或datetime对象相减就可以返回一个timedelta对象. Python中datetime模块中的timedelta ...
- POJ 3122 Pie【二分答案】
<题目链接> 题目大意: 将n个半径不一但是高度为1的蛋糕分给 F+1个人,每个人分得蛋糕的体积应当相同,并且需要注意的是,每个人分得的整块蛋糕都只能从一个蛋糕上切下来,而不是从几个蛋糕上 ...
- 20172328《程序设计与数据结构》实验四 Android程序设计报告
20172328<程序设计与数据结构>实验四 Android程序设计报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 李馨雨 学号:20172328 实验教师:王志 ...
- Oracle date 详解
oracle 数据类型详解---日期型 oracle数据类型看起来非常简单,但用起来会发现有许多知识点,本文是我对ORACLE日期数据类型的一些整理,都是开发入门资料,与大家分享:注:由于INTERV ...
- Centos中安装perl
1.安装gcc,在虚拟机命令窗口中输入:yum install -y gcc 2.下载perl安装包输入命令:wget http://www.cpan.org/src/5.0/perl-5.16.1. ...
- 备份LeetCode OJ自己编写的代码
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...
- C#文件及数据流技术
空间名称:Sysytem.IO 一.文件.文件夹操作1.创建.删除.移动.复制文件 2.创建.删除.移动.复制文件夹 二.流操作 1.FileSream - 提供读取和写入文件的方式 文本文件的写入与 ...
- Android 蓝牙4.0 BLE (onServicesDiscovered 返回 status 是 129,133时)
Android ble (Bluetooth Low Energy) 蓝牙4.0,也就是说android 4.3+, API level >= 18,且支持蓝牙4.0的手机才可以使用. BLE是 ...
- ZKW线段树入门
Part 1 来说说它的构造 线段树的堆式储存 我们来转成二进制看看 小学生问题:找规律 规律是很显然的 一个节点的父节点是这个数左移1,这个位运算就是低位舍弃,所有数字左移一位 一个节点的子节点是这 ...