問題一覧 > 通常問題

No.2157 Cliff

レベル : / AI推定難易度 : 1600 / 実行時間制限 : 1ケース 6.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 111
作問者 : keisuke6 / テスター : kotamanegi KowerKoint2010 hibit_at
お気に入りにしたユーザー ProblemId : 8898 / 自分の提出
問題文最終更新日: 2022-12-08 23:04:02
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 371 (Asakatsu Presents) (順位表) の他の問題:

Problem Statement

In "Asakatsu", a virtual contest held every morning, $N$ problems are each set from a predetermined difficulty range.

The difference in difficulty between adjacent problems is called a cliff, and large cliffs are generally not well liked.

Therefore, when selecting problems, it is desirable to make the cliffs small.

The following task is a generalization of this.

Each of the $N$ difficulty ranges $D_i$ contains $M$ problems, given as $D_{i,j}$.

Using these, define each element of a problem set $A$ as follows.

  • $A_i(1\leq{i}\leq{N})$ is chosen as one of the problems in difficulty range $D_i$.

However, $A$ must be a non-decreasing sequence.

That is, $A_i \leq A_{i+1}$ must hold for every $1 \leq i \leq N-1$.

Here, define $f(A)$ for $A$ as "the maximum value of $A_{i+1}-A_i$ over all $i$". Find the minimum value of $f(A)$.

If no $A$ satisfying the condition exists, output -1.

Input

$N\ M$ 
$D_{1,1} , D_{1,2} , \cdots , D_{1,M}$
$D_{2,1} , D_{2,2} , \cdots , D_{2,M}$
$\hspace{8pt}\vdots \hspace{19pt} \vdots \hspace{9pt}\ddots \hspace{11pt}\vdots$
$D_{N,1} , D_{N,2} , \cdots , D_{N,M}$

  • $1\leq{N,M}\leq{1500}$
  • $1\leq{D_{i,j}}\leq{10^9}$

Output

Output the minimum value of $f(A)$ on one line. If no $A$ satisfying the condition exists, output -1.

Sample

Sample 1
Input
2 2
5 8
12 7
Output
2

$A=(5,7)$ is optimal.

Sample 2
Input
4 4
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
Output
0

$A=(4,4,4,4)$ is optimal.

Sample 3
Input
3 2
2 4
1 5
3 2
Output
-1

If no $A$ satisfying the condition exists, output -1.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。