#BS0000328. Giãn cách trên đồng cỏ (Social Distancing)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Giãn cách trên đồng cỏ (Social Distancing)
Social Distancing
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
Farmer John wants his cows well separated to reduce disease transmission. Model the farm as a line with grass on closed intervals that share no points, including endpoints.
Each cow must stand at an integer coordinate on grass; interval endpoints are allowed. All cows must occupy distinct positions, and enough such positions are guaranteed.
For an arrangement, let be the smallest distance between any pair of cows. Determine the largest possible .
Input
The first line contains two integers , the number of cows and grass intervals.
Each of the following lines contains two integers , the endpoints of interval . The intervals need not be listed in coordinate order.
Output
Print one positive integer: the largest possible .
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input 1
5 3
0 2
4 7
9 9
Output 1
2
Explanation
Place cows at 0, 2, 4, 6 and 9, giving consecutive gaps 2, 2, 2 and 3. A minimum gap of 3 would require a span of at least , exceeding the available span of 9.