CF883I.Photo Processing

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Evlampiy has found one more cool application to process photos. However the application has certain limitations.

Each photo ii has a contrast viv_{i} . In order for the processing to be truly of high quality, the application must receive at least kk photos with contrasts which differ as little as possible.

Evlampiy already knows the contrast viv_{i} for each of his nn photos. Now he wants to split the photos into groups, so that each group contains at least kk photos. As a result, each photo must belong to exactly one group.

He considers a processing time of the jj -th group to be the difference between the maximum and minimum values of viv_{i} in the group. Because of multithreading the processing time of a division into groups is the maximum processing time among all groups.

Split nn photos into groups in a such way that the processing time of the division is the minimum possible, i.e. that the the maximum processing time over all groups as least as possible.

输入格式

The first line contains two integers nn and kk ( 1<=k<=n<=31051<=k<=n<=3·10^{5} ) — number of photos and minimum size of a group.

The second line contains nn integers v1,v2,...,vnv_{1},v_{2},...,v_{n} ( 1<=vi<=1091<=v_{i}<=10^{9} ), where viv_{i} is the contrast of the ii -th photo.

输出格式

Print the minimal processing time of the division into groups.

输入输出样例

  • 输入#1

    5 2
    50 110 130 40 120
    

    输出#1

    20
    
  • 输入#2

    4 1
    2 3 4 1
    

    输出#2

    0
    

说明/提示

In the first example the photos should be split into 2 groups: [40,50][40,50] and [110,120,130][110,120,130] . The processing time of the first group is 1010 , and the processing time of the second group is 2020 . Maximum among 1010 and 2020 is 2020 . It is impossible to split the photos into groups in a such way that the processing time of division is less than 2020 .

In the second example the photos should be split into four groups, each containing one photo. So the minimal possible processing time of a division is 00 .

首页