#P9762. Balanced Split of a Number Table
Balanced Split of a Number Table
Balanced Split of a Number Table
Consider an ( n \times m ) table ( a ) where each element is defined as ( a_{i,j} = (i-1)\times m + j ). You are allowed to make a single straight cut along the table either vertically (i.e. between columns ( i-1 ) and ( i ) for some ( 2 \le i \le m )) or horizontally (i.e. between rows ( i-1 ) and ( i ) for some ( 2 \le i \le n )). This cut splits the table into two sub-tables, denoted by ( x ) and ( y ). The objective is to choose a cut that minimizes ( \max{\sum x,;\sum y} ). Note that the total sum of all elements in the table is [ S = \frac{n \times m \times (n \times m + 1)}{2}. ] Your task is to design a scheme (i.e. choose a cut type and cut index) that achieves this goal. In the output, print the chosen cut as well as the minimized maximum sum. If you choose the vertical cut, output it as "VERTICAL j" where ( j ) is the number of columns in the left part; if you choose the horizontal cut, output it as "HORIZONTAL i" where ( i ) is the number of rows in the top part. The next line should contain the minimized maximum sum.
inputFormat
The input consists of a single line with two integers ( n ) and ( m ) (( n, m \ge 2 )), separated by a space.
outputFormat
Output two lines. The first line should contain the chosen cut type and index (either "VERTICAL j" or "HORIZONTAL i"). The second line should contain the minimized maximum sum after the cut.
sample
2 2
VERTICAL 1
6
</p>