CF883I.Photo Processing
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Evlampiy has found one more cool application to process photos. However the application has certain limitations.
Each photo i has a contrast v__i. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible.
Evlampiy already knows the contrast v__i for each of his n photos. Now he wants to split the photos into groups, so that each group contains at least k photos. As a result, each photo must belong to exactly one group.
He considers a processing time of the j-th group to be the difference between the maximum and minimum values of v__i in the group. Because of multithreading the processing time of a division into groups is the maximum processing time among all groups.
Split n 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.
埃夫拉姆皮已经找到了另一款用于处理照片的酷炫应用,但该应用存在某些限制。
每张照片 i 具有一个对比度 vi。为了确保处理质量真正达到高水平,该应用必须接收至少 k 张对比度尽可能接近的照片。
埃夫拉姆皮已知他全部 n 张照片各自的对比度 vi。现在,他希望将这些照片划分为若干组,使得每组至少包含 k 张照片;并且每张照片必须且仅能属于其中一组。
他将第 j 组的处理时间定义为该组内所有 vi 的最大值与最小值之差。由于应用支持多线程,整个分组方案的处理时间为所有组处理时间中的最大值。
请将这 n 张照片划分为若干组,使得整个分组方案的处理时间(即所有组处理时间的最大值)尽可能小。
输入格式
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — number of photos and minimum size of a group.
The second line contains n integers _v_1, _v_2, ..., v__n (1 ≤ v__i ≤ 109), where v__i is the contrast of the i-th photo.
第一行包含两个整数 n 和 k(1 ≤ k ≤ n ≤ 3⋅105)——照片数量和组的最小大小。
第二行包含 n 个整数 v1,v2,...,vn(1 ≤ vi ≤ 109),其中 vi 表示第 i 张照片的对比度。
输出格式
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] and [110, 120, 130]. The processing time of the first group is 10, and the processing time of the second group is 20. Maximum among 10 and 20 is 20. It is impossible to split the photos into groups in a such way that the processing time of division is less than 20.
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 0.
在第一个例子中,照片应被分为两组:[40, 50] 和 [110, 120, 130]。第一组的处理时间为 10,第二组的处理时间为 20。10 和 20 中的最大值为 20。不存在一种分组方式,使得该划分的处理时间小于 20。
在第二个例子中,照片应被分为四组,每组包含一张照片。因此,划分的最小可能处理时间为 0。
输入解题思路,AI测评打分。不知道怎么写?