#P3474. Industrial Plot Purchase

    ID: 16729 Type: Default 1000ms 256MiB

Industrial Plot Purchase

Industrial Plot Purchase

Byteasar wants to buy an industrial plot and is looking to spend an amount between \( k \) and \( 2k \) bythalers. The area is given as an \( n \times n \) grid where each cell represents the price per square metre. A valid plot is a rectangular (subgrid) region composed of whole unit squares whose total price lies within the interval \([k,2k]\). If a valid plot exists, output its coordinates as four integers indicating its top‐left cell and bottom‐right cell (using 1-indexing). Otherwise, output NO.

inputFormat

The first line contains two integers \( k \) and \( n \) (\( 1 \le k \le ... \) and \( 1 \le n \le ... \)). The next \( n \) lines each contain \( n \) integers. The \( j \)th number in the \( i \)th line is the price (in bythalers) of the unit square at row \( i \) and column \( j \).

outputFormat

If a suitable rectangular plot is found, output four integers \( r_1 \), \( c_1 \), \( r_2 \) and \( c_2 \) (1-indexed) representing the top-left and bottom-right corners of the rectangle. If no such plot exists, output NO.

sample

5 3
1 7 3
7 2 8
5 1 2
1 1 1 2