#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <Map>
#include <set>
#include <vector>
using namespace std;
int n;
__int64 tm[2005][2005];
__int64 L[2005*2];//副对角线元素之和
__int64 R[2005*2]; //主对角线元素之和
int main()
{
__int64 i,j;
cin>>n;
for (i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%I64d",&tm[i][j]);
L[i+j] +=tm[i][j];//同一条副对角线i+j相同
R[i-j+n] +=tm[i][j];//同一条主对角线i-j相同
}
}
int rx=1;
int ry=1;
int x1=1;
int y1=2;
__int64 max2=0;
__int64 max1=0;
__int64 tmp=0;
for (i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
tmp=L[i+j]+R[i-j+n]-tm[i][j];
if ((i+j)%2==0 && tmp>max1)
{
max1=tmp;
x1=i;
y1=j;
}
if ((i+j)%2==1 && tmp>max2)
{
max2=tmp;
rx=i;
ry=j;
}
}
}
printf("%I64d\n", max1 + max2);
printf("%d %d %d %d\n",x1,y1,rx,ry);
return 0;
}
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.
He has a n × n chessboard. 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 number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars 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).