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. multiselect2side双向选择列表插件改进版

    为了满足实际程序需要,特在multiselect2side插件的基础上改进已满足异步加载(如MVC)的需要.增加了加载url.saveurl属性以及控件实时刷新加载数据方法,请注意下面红色标记部分. ...

  2. python跟踪脚本进度(类似bash-x)

    #详细追踪 python -m trace --trace jin.py #显示调用了哪些函数 python -m trace --trackcalls jin.py

  3. I.MX6 build.prop

    /************************************************************************ * I.MX6 build.prop * 说明: * ...

  4. I.MX6 U-boot PWM hacking

    /******************************************************************************* * I.MX6 U-boot PWM ...

  5. Ext基础一(转载)

    要学习及应用好Ext框架,必须需要理解Html DOM.Ext Element及Component三者之间的区别. 每一个HTML页面都有一个层次分明的DOM树模型,浏览器中的所有内容都有相应的DOM ...

  6. 我的WCF之旅(1):创建一个简单的WCF程序

    为了使读者对基于WCF的编程模型有一个直观的映像,我将带领读者一步一步地创建一个完整的WCF应用.本应用功能虽然简单,但它涵盖了一个完整WCF应用的基本结构.对那些对WCF不是很了解的读者来说,这个例 ...

  7. docker专题(2):docker常用管理命令(上)

    http://segmentfault.com/a/1190000000751601 本文只记录docker命令在大部分情境下的使用,如果想了解每一个选项的细节,请参考官方文档,这里只作为自己以后的备 ...

  8. [selenium webdriver Java]处理弹出窗口

    Selenium WebDriver测试弹出窗口,包括识别弹出窗口,将driver转到新的窗口,在新的串钩中执行而是步骤,然后再转换到最初的窗口. 通过名称(name)识别和处理: Selenium ...

  9. STM32的can现场总线实验心得

    最近在搞stm32实验板的can现场总线实验,之前只是搞过STC51的串口通信,相比之下,发觉can总线都挺复杂的.开始时,知道自己是新手,只知道can总线跟串行通信,485通信,I2C通信一样都是用 ...

  10. 简单的activemq的封装和使用

    天空中飘着小雨,实在是适合写代码的时节. 1 package ch02.chat; import java.io.Serializable; import javax.jms.Connection; ...