{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"FJ has decided to grow his own corn hybrid in order to help the cows make the best possible milk. To that end, he\u0027s looking to build the cornfield on the flattest piece of land he can find.\r\u003cbr\u003e\r\u003cbr\u003eFJ has, at great expense, surveyed his square farm of N x N hectares (1 \u0026lt;\u003d N \u0026lt;\u003d 250). Each hectare has an integer elevation (0 \u0026lt;\u003d elevation \u0026lt;\u003d 250) associated with it.\r\u003cbr\u003e\r\u003cbr\u003eFJ will present your program with the elevations and a set of K (1 \u0026lt;\u003d K \u0026lt;\u003d 100,000) queries of the form \"in this B x B submatrix, what is the maximum and minimum elevation?\". The integer B (1 \u0026lt;\u003d B \u0026lt;\u003d 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.\r\u003cbr\u003e"}},{"title":"Input","value":{"format":"HTML","content":"* Line 1: Three space-separated integers: N, B, and K.\r\u003cbr\u003e\r\u003cbr\u003e* 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.\r\u003cbr\u003e\r\u003cbr\u003e* 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.\r\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"* Lines 1..K: A single integer per line representing the difference between the max and the min in each query.\r\u003cbr\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5 3 1\r\n5 1 2 6 3\r\n1 3 5 2 7\r\n7 2 4 6 1\r\n9 9 8 6 5\r\n0 6 9 3 9\r\n1 2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e5\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}