1086. Max discrepancy

单点时限: 2.0 sec

内存限制: 256 MB

Solofanfy is busy with his farm,at this time,his little dog ask him to do some algorithm with his farmland,

Solofanfy has, at great expense, surveyed his square farm of N x N hectares (1 <= N <= 250). Each hectare has an integer elevation (0 <= elevation <= 250) associated with it.

Solofanfy will present your program with the elevations and a set of K (1 <= K <= 100,000) queries of the form “in this B x B submatrix, what is the maximum and minimum elevation?”. The integer B (1 <= B <= N) is the size of one edge of the square cornfield and is a constant for every inquiry. Help FJ find the best place to put his cornfield.

输入格式

There are many test cases.

  • Line 1: Three space-separated integers: N, B, and K.

  • Lines 2..N+1: Each line contains N space-separated integers. Line 2 represents row 1; line 3 represents row 2, etc. The first integer on each line represents column 1; the second integer represents column 2; etc.

  • Lines N+2..N+K+1: Each line contains two space-separated integers representing a query. The first integer is the top row of the query; the second integer is the left column of the query. The integers are in the range 1..N-B+1.

输出格式

  • Lines 1..K: A single integer per line representing the difference between the max and the min in each query.

样例

Input
5 3 2
65 49 26 70 9
67 85 18 59 1
36 96 89 48 68
66 93 46 99 55
66 11 59 75 80
1 1
2 2
Output
78
81

28 人解决,41 人已尝试。

48 份提交通过,共有 150 份提交。

4.8 EMB 奖励。

创建: 17 年,8 月前.

修改: 7 年,2 月前.

最后提交: 3 年,12 月前.

来源: sunny_fable

题目标签