Find two bishops on an board, one on a black square and one on a white square, such that the sum of values on both bishops' diagonals is maximized.
You are given an table of integers. Consider placing a bishop on any cell of the board.
A bishop attacks every cell on the two diagonals passing through its position. For a bishop placed at cell , define its score as the sum of all values on both diagonals that pass through , counting the cell itself only once.
Choose two cells:
so that the sum of their scores is as large as possible.
Return the maximum possible total score and the coordinates of the two chosen cells.
The standard chessboard coloring is used: a cell is black if is even, otherwise white.
Print the maximum total score, followed by the coordinates of the chosen black cell and white cell.
If multiple answers exist, any valid one may be returned.
Print four integers for the best black cell and four integers for the best white cell, or otherwise the maximal total value and coordinates in the required order depending on the implementation format used by the platform.
For practice purposes, the key goal is to compute:
Example 1
Input
2 1 2 3 4
Output
8 1 2 2 1
Explanation
Cell has diagonal sum and cell has diagonal sum if diagonals are counted over the board; since each cell belongs to one black and one white square, the best valid pair is one black and one white cell. This tiny example illustrates the idea of evaluating both colors separately.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.