Codeforces Round #264 (Div. 2) C (query rule)

Source: Internet
Author: User

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 ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.