[POI2008] KUP-Plot purchase

题目描述

Byteasar is going to buy an industrial plot. His fortune is estimated at $k$ bythalers and this is exactly the amount Byteasar would like to spend on the parcel. Finding a parcel worth exactly $k$ bythalers, however, is not an easy task. For this reason Byteasar is ready to buy a more expensive plot. He considers taking out a loan. The Byteotian Credit Bank will grant him a loan of up to $k$ bythalers. Thus, Byteasar can spend no more than $2k$ bythalers on the parcel and he would like to spend no less than $k$ bythalers. The area in which Byteasar wants to buy his parcel is a square with side length of $n$ metres. The current landlords have set up various prices per square metre. Byteasar has spoken to each one of them and has then prepared a price map of the area. The map depicts the price of every metre by metre square. Clearly, there are $n^2$ such squares. Now is the time to find the dream parcel. It has to be rectangular and consist of whole unit squares. Byteasar has already started looking for the plot on the map, but after many hours he was still unable to find a suitable one. Be a chap and help him! <Task> Write a programme that: reads the numbers $k$ and $n$ from the standard input, along with the price map of the area, determines a parcel with price in the interval $[k,2k]$ or states that no such parcel exists, writes out the result to the standard output.

输入输出格式

输入格式


The first line of the standard input contains two integers, $k$ and $n$, separated by a single space, $1\le k\le 10^9$, $1\le n\le 2000$. Each of the following $n$ lines contains $n$ non-negative integers, separated by single spaces. $i^\mathrm{th}$ number in the line no. $j+1$ denotes the price of unit square with coordinates $(i,j)$. The price of one square metre does not exceed $2{,}000{,}000{,}000$ bythalers.

输出格式


If no plot with price in the interval $[k,2k]$ exists, your programme should output exactly one line with word `NIE` (NO in Polish). Otherwise it should print out one line with four positive integers $x_1,y_1,x_2,y_2$ separated by single spaces and denoting the rectangle's coordinates. $(x_1,y_1)$ denotes the upper left rectangle corner, while $(x_2,y_2)$ the lower right corner. Then it consists of the squares: $\{x,y\mid x_1\le x\le x_2,y_1\le y\le y_2\}$. The sum $c$ of prices of the squares forming up this rectangle should satisfy the inequality $k\le c\le 2k$. If more than one rectangular parcel satisfies this condition, pick one arbitrarily.

输入输出样例

输入样例 #1

8 4
1 2 1 3
25 1 2 1
4 20 3 3
3 30 12 2

输出样例 #1

2 1 4 2

说明

给定 $k,n$ 和 $n\times n$ 的矩阵,求一个子矩形满足权值和在 $[k,2k]$ 之间。 $n<2000$,$1\le k\le10^9$,每个价格都是不大于$2 \times 10^9$ 的非负整数。 感谢@cn:苏卿念 提供的spj