#BS0000326. Lực từ giữa các quả bóng (Magnetic Force Between Two Balls)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lực từ giữa các quả bóng (Magnetic Force Between Two Balls)
Magnetic Force Between Two Balls
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Rick has empty baskets on a line, with basket at the distinct integer coordinate . Morty must place exactly balls, at most one in each basket.
The magnetic force between balls at and is defined as . For a placement, consider the smallest force among all pairs of balls.
Choose baskets to maximize that smallest force.
Input
The first line contains two integers , the numbers of baskets and balls.
The second line contains integers , the basket coordinates.
Output
Print one integer: the maximum achievable minimum magnetic force.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input 1
5 3
1 2 3 4 7
Output 1
3
Explanation
Use baskets at 1, 4 and 7. The forces are 3, 3 and 6, so the minimum is 3. Three balls with minimum gap 4 would need a span of at least 8, but the available span is only 6.

Input 2
6 2
5 4 3 2 1 1000000000
Output 2
999999999
Explanation
Use coordinates 1 and . Their difference is , the entire available span, so no larger force is possible.