#P10710. [NOISG 2024 Prelim] School Photo

    ID: 12201 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2024双指针 two-pointerNOISG(新加坡)

[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 nn classes, and each class has ss students. The height of the jj-th student in the ii-th class is ai,ja_{i,j}.

Now Zane wants to choose one student from each class for a photo, such that among these nn 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 n,sn, s.

The next nn lines each contain ss integers, representing aa.

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 a1,3,a2,2,a3,2a_{1,3}, a_{2,2}, a_{3,2}. The answer is 84=48-4=4.

Constraints

Subtask\text{Subtask} Score Special Property
00 Samples
11 1111 n=2n=2
22 2222 n,s100n, s \le 100
33 99 n,s250n, s \le 250
44 3333 n,s500n, s \le 500
55 2525 None

For 100%100\% of the testdata, 1n,s10001 \le n, s \le 1000, and 1ai,j1091 \le a_{i,j} \le 10^9.

Translated by ChatGPT 5