#BS0000419. Xử lý ảnh (Photo Processing)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xử lý ảnh (Photo Processing)
Photo Processing
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are photos with contrast values . Partition them into groups so that each photo belongs to exactly one group and each group contains at least photos. Photos in a group need not be consecutive in their original order.
The processing time of a group is its largest contrast minus its smallest contrast. Groups run in parallel, so the overall time is the largest of their processing times.
Find the minimum possible overall time.
Input
The first line contains integers .
The second line contains integers .
Output
Print the minimum overall time as an integer.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input 1
5 2
50 110 130 40 120
Output 1
20
Explanation 1
The groups [40,50] and [110,120,130] have spreads 10 and 20. A smaller bound cannot accommodate the last three photos.
Input 2
4 1
2 3 4 1
Output 2
0
Explanation 2
Singleton groups have zero spread.