Description

It is raining again! Youssef really forgot that there is a chance of rain in March, so he didn't fix the roof of his house. Youssef's roof is 1-D, and it contains n holes that make the water flow into the house, the position of hole i is denoted as xi where (0 ≤ i < n). Youssef has to put strips at the bottoms of those holes in order to prevent the water from flowing. Let's say there is a hole in position 4 and another hole in position 6, and Youssef decided to use a strip of length 3 to cover those two holes, then he places the strip from position 4 to 6 (it covers positions 4,5,6) and it covers the two holes. He can buy exactly k strips, and he must pay a price equal to the longest strip he buys. What is the minimum length l he can choose as the longest strip in order to keep his house safe?

Input

The input consists of several test cases. The first line of the input contains a single integer T, the number of the test cases. Each test case consists of two lines: the first line contains two space-separated integers, n and k (1 ≤ k < n ≤ 100000), denoting the number of the holes in the roof, and the number of the strips he can buy respectively. The second line of the test case contains n integers (x0, x1, ..., xn - 1): (0 ≤ xi ≤ 109), denoting the positions of holes (these numbers are given in an increasing order).

Output

For each test case print a single line containing a single integer denoting the minimum length l he can choose in order to buy k strips (the longest of them is of length l) and cover all the holes in his house using them.

Example
input
3
5 2
1 2 3 4 5
7 3
1 3 8 9 10 14 17
5 3
1 2 3 4 20
output
3
4
2
Note
                                 

In the second test case the roof looks like this before and after putting the strips.

题意:屋顶漏水,现在知道xi处是漏的,可以使用k块布盖住,问最短布的长度为多少

解法:二分,首先当然是最大的数字/k,得到最长的长度,然后二分判断

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int a[100005];
int main(){
int T;
scanf("%d",&T);
while(T--){
int n,m;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
int l=0,r=a[n-1]/m+1;
while(l<=r){
int mid=(l+r)/2;
int x=a[0]+mid-1,cnt=1;
for(int i=0;i<n;i++){
if(a[i]>x){
cnt++;
x=a[i]+mid-1;
}
}
if(cnt<=m){
r=mid-1;
}else{
l=mid+1;
}
}
printf("%d\n",r+1);
}
}

  

2016 Al-Baath University Training Camp Contest-1 I的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest)

    2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest) Problem A. M ...

  3. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  4. 2016 Al-Baath University Training Camp Contest-1 B

    Description A group of junior programmers are attending an advanced programming camp, where they lea ...

  5. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  6. 2016 Al-Baath University Training Camp Contest-1 J

    Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...

  7. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

  8. 2016 Al-Baath University Training Camp Contest-1 G

    Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...

  9. 2016 Al-Baath University Training Camp Contest-1 F

    Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...

随机推荐

  1. acm pc^2的配置与使用

    -------------------------------------------------------------------------------------- !!! 转载请注明: 转自 ...

  2. 根据搜素的字符串改变label包含该字符串的文字

    http://www.2cto.com/kf/201504/391811.html NSString *text =@"人生若只如初见"; //判断字符串所在的位置,并不区分大小写 ...

  3. extjs4.0下的日期控件的星期显示为y的解决办法

    没有修改的时候的问题: 今天第一次写博客,就记录一下以前extjs4.2下运用日期组件的星期显示问题,当时找了n久,可能是extjs4.2才出来没多久,没有多少人发现这个问题或者说很少有人将Extjs ...

  4. ruby的在ubuntu上的安装

    apt (Debian or Ubuntu) Debian GNU/Linux and Ubuntu use the apt package manager. You can use it like ...

  5. Cookie—的使用

    编写 Cookie 浏览器负责管理用户系统上的 Cookie.Cookie 通过 HttpResponse 对象发送到浏览器,该对象公开称为 Cookies 的集合. 可以将 HttpResponse ...

  6. WebForm中<%=%>与<%#%>的区别?

    1<%=%>相当于Response.Write(),是输出变量的值 2<%#%>专门用于数据绑定,可以绑定一些变量或者数据源中的信息,中间绑定是数据源的条目,若想让它起作用,必 ...

  7. 夺命雷公狗---Thinkphp----15之遍历出来的栏目页的完成

    我们首页的写法和我们的文章页的代码很相似,我们要在点击我们的栏目页的时候遍历出对应的代码: 那么我们就直接来创建一个ListsController.class.php的文件,代码如下所示: 老规矩遍历 ...

  8. LDA-math-神奇的Gamma函数

    http://cos.name/2013/01/lda-math-gamma-function/ 1. 神奇的Gamma函数1.1 Gamma 函数诞生记学高等数学的时候,我们都学习过如下一个长相有点 ...

  9. 《zw版·Halcon-delphi系列原创教程》航母舰载机·视觉定位标志的识别代码

    <zw版·Halcon-delphi系列原创教程>航母舰载机·视觉定位标志的识别代码 航母舰载机机身上的黄黑圆圈的标志是什么意思,辐射?核动力?战术核弹? <百度百科>介绍如下 ...

  10. zw版【转发·台湾nvp系列Delphi例程】HALCON Histogram

    zw版[转发·台湾nvp系列Delphi例程]HALCON Histogram unit Unit1;interfaceuses Windows, Messages, SysUtils, Varian ...