QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 100

#16138. Ideal Square

Statistiques

You are given an $a \times b$ matrix of integers. Please find an $n \times n$ square region within it such that the difference between the maximum and minimum values in that region is minimized.

Input

The first line contains three integers, representing the values of $a$, $b$, and $n$.

The next $a$ lines each contain $b$ non-negative integers, representing the numbers at the corresponding positions in the matrix. Adjacent numbers in each line are separated by a space.

Output

A single integer, which is the minimum value of the "difference between the maximum and minimum integers in an $n \times n$ square region" among all such regions in the $a \times b$ matrix.

Examples

Input 1

5 4 2
1 2 5 6
0 17 16 0
16 17 2 1
2 10 2 1
1 2 2 2

Output 1

1

Constraints

(1) All numbers in the matrix do not exceed $1,000,000,000$.

(2) For 20% of the data: $2 \le a, b \le 100$, $n \le a$, $n \le b$, $n \le 10$.

(3) For 100% of the data: $2 \le a, b \le 1000$, $n \le a$, $n \le b$, $n \le 100$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.