#P10710. [NOISG 2024 Prelim] School Photo
[NOISG 2024 Prelim] School Photo
Background
Translated from NOI SG 2024 Prelim C.School Photo.
Problem Description
Zane is the principal of the NOI school. The NOI school has classes, and each class has students. The height of the -th student in the -th class is .
Now Zane wants to choose one student from each class for a photo, such that among these students, the difference between the tallest student's height and the shortest student's height is minimized.
Output this minimum value.
Input Format
The first line contains two integers .
The next lines each contain integers, representing .
Output Format
Output one integer in a single line, representing the answer.
2 3
2 1 8
5 4 7
1
3 3
3 1 4
2 7 18
9 8 10
4
Hint
Sample #2 Explanation
Choose . The answer is .
Constraints
| Score | Special Property | |
|---|---|---|
| Samples | ||
| None | ||
For of the testdata, , and .
Translated by ChatGPT 5