#d11103. 新年的问题(数据加强版)

新年的问题(数据加强版)

New Year's Problem (Enhanced Version)

Problem Description

Given an n×mn \times m matrix, you must choose exactly one number from each column, such that among these chosen numbers there exist two that are in the same row. Maximize the minimum of these mm chosen numbers, and output that value.

Input Format

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

The next nn lines each contain mm positive integers.

Output Format

One positive integer.

Sample Input

2 2
1 2
3 4

Sample Output

3

Sample Explanation

m=2m = 2, which requires choosing from at most 2−1=12 - 1 = 1 row, i.e. only one row can be chosen. Choosing the first row gives 1,21, 2 with minimum 11; choosing the second row gives 3,43, 4 with minimum 33. So the answer is 33.

Constraints

2<n,m≤25002 < n, m \le 2500.

All numbers appearing are at most 10910^9.

  • Further note: A binary search solution can pass after optimizing input, but you may also try an O(nm)O(nm) approach.