C. Read Time

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/343/problem/C

Description

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.

​i​​(A​i​​≤10​6​​) 分,之后每过一分钟这道题目的分值会减少 BiB_iB​i​​ 分,并且保证到比赛结束时分值不会减少为负值。比如,一个人在第 xxx 分钟结束时做出了第 iii 道题目,那么他/她可以得到 Ai−Bi∗xA_i - B_i * xA​i​​−B​i​​∗x 分。
若一名选手在第 xxx 分钟结束时做完了一道题目,则他/她可以在第 x+1x+1x+1 分钟开始时立即开始做另一道题目。
参加省队选拔的选手 dxy 具有绝佳的实力,他可以准确预测自己做每道题目所要花费的时间,做第 iii 道需要花费 Ci(Ci≤t)C_i(C_i \leq t)C​i​​(C​i​​≤t) 分钟。由于 dxy 非常神,他会做所有的题目。但是由于比赛时间有限,他可能无法做完所有的题目。他希望安排一个做题的顺序,在比赛结束之前得到尽量多的分数

Input

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.,B​i​​,C​i​​,即此题的初始分值、每分钟减少的分值、dxy做这道题需要花费的时间。

Output

Print a single number — the minimum time required, in seconds, to read all the needed tracks.

Sample Input

3 4
2 5 6
1 3 6 8

Sample Output

2

HINT

题意

有n个刷子,每个刷子都可以左移动和右移动,每移动一格是1秒

然后问你最少多少秒,可以让这n个刷子把这m个接口都刷完

题解:

二分时间之后check就好

check注意可以先往左再往右,也可以先往右再往左的

注意一下就好啦

代码:

#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std; long long a[];
long long b[];
int n,m;
long long abs(long long a)
{
if(a<)return -a;
return a;
}
int judge(long long t)
{
int tot = ;
int l=,r=;
for(int i=;i<=n;i++)
{
long long ans = abs(b[r]-b[l]) + min(abs(b[r]-a[i]),abs(b[l]-a[i]));
while(r<=m&&ans<=t)
{
r++;
ans = abs(b[r]-b[l]) + min(abs(b[r]-a[i]),abs(b[l]-a[i]));
}
l=r;
if(r==m+)return ;
}
return ;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=;i<=m;i++)
scanf("%lld",&b[i]);
long long l = ,r = 2e10;
while(l<=r)
{
long long mid = (l+r)/2LL;
if(judge(mid))r = mid - ;
else l = mid + ;
}
cout<<l<<endl;
}

Codeforces Round #200 (Div. 1) C. Read Time 二分的更多相关文章

  1. Codeforces Round #200 (Div. 2) E. Read Time(二分)

    题目链接 这题,关键不是二分,而是如果在t的时间内,将n个头,刷完这m个磁盘. 看了一下题解,完全不知怎么弄.用一个指针从pre,枚举m,讨论一下.只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的 ...

  2. Codeforces Round #200 (Div. 1)A. Rational Resistance 数学

    A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  3. Codeforces Round #200 (Div. 1)D. Water Tree dfs序

    D. Water Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/ ...

  4. Codeforces Round #200 (Div. 1) B. Alternating Current 栈

    B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  5. Codeforces Round #200 (Div. 2) C. Rational Resistance

    C. Rational Resistance time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #200 (Div. 1) BCD

    为了锻炼个人能力奋力div1 为了不做原题从200开始 B 两个电线缠在一起了 能不能抓住两头一扯就给扯分开 很明显当len为odd的时候无解 当len为偶数的时候 可以任选一段长度为even的相同字 ...

  7. Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)

    D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Round #200 (Div. 1) D. Water Tree(dfs序加线段树)

    思路: dfs序其实是很水的东西.  和树链剖分一样, 都是对树链的hash. 该题做法是:每次对子树全部赋值为1,对一个点赋值为0,查询子树最小值. 该题需要注意的是:当我们对一棵子树全都赋值为1的 ...

  9. Codeforces Round #200 (Div. 1) D Water Tree 树链剖分 or dfs序

    Water Tree 给出一棵树,有三种操作: 1 x:把以x为子树的节点全部置为1 2 x:把x以及他的所有祖先全部置为0 3 x:询问节点x的值 分析: 昨晚看完题,马上想到直接树链剖分,在记录时 ...

随机推荐

  1. string.Join和string.Concat的区别

    源自Difference between String.Join() vs String.Concat() With .NET 4.0, String.Join() uses StringBuilde ...

  2. Zookeeper基本知识

    Zookeeper的Session: (1)客户端和server间采用长连接 (2)连接建立后,server产生session ID(64位)返还给客户端 (3)客户端定期发送ping包来检查和保持和 ...

  3. Hadoop伪分布模式配置部署

    .实验环境说明 注意:本实验需要按照上一节单机模式部署后继续进行操作 1. 环境登录 无需密码自动登录,系统用户名 shiyanlou,密码 shiyanlou 2. 环境介绍 本实验环境采用带桌面的 ...

  4. bzoj1196:[Hnoi2010]chorus 合唱队

    这数据范围明显的区间dp啊...然而据说二维会wa...那就写三维把... #include<cstdio> #include<cstring> #include<cct ...

  5. PhpStorm快捷键设置/个性化设置,

    #常用快捷键 设置快捷键:File -> Settings -> IDE Settings -> Keymap -> 选择“Eclipse” -> 然后“Copy”一份 ...

  6. iOS使用WSDL2ObjC工具调用Webservice接口

    1. 下载 WSDL2ObjC.app https://code.google.com/archive/p/wsdl2objc/downloads 2:下载WSDL文件 2.1一般情况下, 你会得到这 ...

  7. liunx环境下安装mysql数据库

    一:如果你的机器上之前安装有mysql数据库,先进行卸载 (1)需要先将它的文件删除 (2)同时注意删除老板本的etc/my.cnf文件和/etc/mysql目录,这两个文件控制的是mysql的一些配 ...

  8. Erlang入门(一)

    读erlang.org上面的Erlang Course四天教程1.数字类型,需要注意两点1)B#Val表示以B进制存储的数字Val,比如 7> 2#101.5 二进制存储的101就是10进制的5 ...

  9. Uva11732(trie)

    题意:给你n个字符串 用strcmp()两两比较 ,求字符比较的总次数 分析: 数据量很大我们考虑用孩子兄弟表示法来表示字典树 #include <cstdio> #include < ...

  10. e2e 自动化集成测试 架构 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step (三) SqlServer数据库的访问

    上一篇文章“e2e 自动化集成测试 架构 京东 商品搜索 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step 二 图片验证码的识别” ...