#B4470. 矩阵游戏 / matrix

    ID: 16868 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>博弈论2025O2优化排序山西双指针 two-pointer科创活动小学活动

矩阵游戏 / matrix

Problem Description

Xiaoshan and Xiaoxi are playing a matrix game:

There is an n×mn \times m matrix. Xiaoshan can choose a value for each row as the representative value of that row. Xiaoxi will then select two numbers from these representative values and take the absolute difference.

Xiaoshan wants the difference chosen by Xiaoxi to be as small as possible; Xiaoxi wants the difference she selects to be as large as possible.

Please calculate, assuming both players adopt optimal strategies, what is the absolute difference between the two representative values that Xiaoxi ultimately selects?

Input Format

The first line contains two integers n,mn, m.

The next nn lines each contain mm integers.

Output Format

An integer representing the final difference.

3 3
1 2 9
4 5 6
7 8 3
2

Hint

[Sample 11 Explanation]

When both choose optimal strategies, Xiaoshan selects {2,4,3}\{2,4,3\} as the representative values for the three rows. From this set, Xiaoxi chooses the two numbers with the largest difference, 22 and 44, resulting in a maximum difference of 42=2|4-2|=2. This is the minimum maximum difference that Xiaoshan can ensure.

[Constraints]

For 10%10\% of the data, m=1m=1.

For another 10%10\% of the data, n=2n=2.

For another 20%20\% of the data, 2n8,2m82 \le n \le 8, 2 \le m \le 8.

For another 30%30\% of the data, 2n100,2m1002 \le n \le 100, 2 \le m \le 100.

For 100%100\% of the data, 2n1000,1m10002 \le n \le 1000, 1 \le m \le 1000, and the absolute values of the integers in the matrix do not exceed 10910^9.


Translated by DeepSeek-V3