A11449 | Photo Processing
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains two integers $n$ and $k$ ( $1<=k<=n<=3·10^{5}$ ) — number of photos and minimum size of a group.
The second line contains $n$ integers $v_{1},v_{2},...,v_{n}$ ( $1<=v_{i}<=10^{9}$ ), where $v_{i}$ is the contrast of the $i$ -th photo.
The second line contains $n$ integers $v_{1},v_{2},...,v_{n}$ ( $1<=v_{i}<=10^{9}$ ), where $v_{i}$ is the contrast of the $i$ -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]$ 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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted