Codeforces Round #264 (Div. 2) C (query rule)
C. Gargari and Bishopstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He hasN? ×?NChessboard. each cell of the chessboard has a number written on it. gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. consider a cell with numberXWritten on it, if this cell is attacked by one of the bishops gargargari will getXDollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.
We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it ).
Input
The first line contains a single integerN(2? ≤?N? ≤? 2000). Each of the nextNLines containsNIntegersAIj(0? ≤?AIj? ≤? 109)-description of the chessboard.
Output
On the first line print the maximal number of dollars gargargari will get. On the next line print four integers:X1 ,?Y1 ,?X2 ,?Y2 (1? ≤?X1 ,?Y1 ,?X2 ,?Y2? ≤?N), WhereXIIs the number of the row whereI-Th bishop shoshould be placed,YIIs the number of the column whereI-Th bishop shoshould be placed. Consider rows are numbered from 1NFrom top to bottom, and columns are numbered from 1NFrom left to right.
If there are several optimal solutions, you can print any of them.
Sample test (s) input
41 1 1 12 1 1 01 1 1 01 0 0 1
Output
122 2 3 2
Select two vertices in the n * n matrix. The sum of vertices covered by these two vertices is the largest, and the vertices covered by these two vertices cannot be the same, A given vertex can be overwritten by another vertex only when they are on the same diagonal line.
Idea: Since the vertices to be covered cannot be the same, suppose a vertex is (I, j), so that v = I + j, the values of these two vertices must be an odd number and an even number. Otherwise, the same vertices will be overwritten no matter how you choose them.
We need to pre-process the sum of each oblique number of rows (left oblique, Right oblique) in the matrix, and traverse the points in the matrix once. The v value of the Split points is the odd number and the even number respectively to record the maximum value, this idea is easy to think of, but it seems a little troublesome to handle. It seems that my code capabilities are not enough, sad ~