#include <iostream>
using namespace std;
long long x[50][50],n,m,a[50][50],ans=-100000000000;
int main()
{
cin>>n>>m;
for(long long i=1;i<=n;++i)
for(long long j=1;j<=m;++j)
{
cin>>a[i][j];
a[i][j]+=i+j;
x[i][j]=a[i][j];
}
for(long long i=n;i>=1;--i)
for(long long j=m;j>=1;--j)
{
if(j<m)
x[i][j]=min(x[i][j],x[i][j+1]);
if(i<n)
x[i][j]=min(x[i][j],x[i+1][j]);
if(ans<a[i][j]-x[i][j]-1)
ans=a[i][j]-x[i][j]-1;
}
for(long long i=n;i>=1;--i)
for(long long j=m;j>=1;--j)
{
a[i][j]-=2*(i+j);
x[i][j]=a[i][j];
if(j<m)
x[i][j]=max(x[i][j],x[i][j+1]);
if(i<n)
x[i][j]=max(x[i][j],x[i+1][j]);
if(ans<x[i][j]-a[i][j]-1)
ans=x[i][j]-a[i][j]-1;
}
for(long long i=1;i<n/2;++i)
for(long long j=1;j<=m;++j)
{
a[i][j]+=i+j;
a[n-i+1][j]+=i+j;
swap(a[i][j],a[n-i+1][j]);
a[i][j]+=i+j;
a[n-i+1][j]+=i+j;
x[i][j]=a[i][j];
x[n-i+1][j]=a[n-i+1][j];
}
if(n%2==0)
{
i=n/2;
for(long long j=1;j<=m;++j)
{
a[i][j]+=i+j;
a[n-i+1][j]+=i+j;
swap(a[i][j],a[n-i+1][j]);
a[i][j]+=i+j;
a[n-i+1][j]+=i+j;
x[i][j]=a[i][j];
x[n-i+1][j]=a[n-i+1][j];
}
}
else
{
i=n/2;
for(long long j=1;j<=m;++j)
{
a[i][j]+=i+j;
a[i][j]+=i+j;
x[i][j]=a[i][j];
}
}
for(long long i=n;i>=1;--i)
for(long long j=m;j>=1;--j)
{
if(j<m)
x[i][j]=min(x[i][j],x[i][j+1]);
if(i<n)
x[i][j]=min(x[i][j],x[i+1][j]);
if(ans<a[i][j]-x[i][j]-1)
ans=a[i][j]-x[i][j]-1;
}
for(long long i=n;i>=1;--i)
for(long long j=m;j>=1;--j)
{
a[i][j]=a[i][j]-2*(i+j);
x[i][j]=a[i][j];
if(j<m)
x[i][j]=max(x[i][j],x[i][j+1]);
if(i<n)
x[i][j]=max(x[i][j],x[i+1][j]);
if(ans<x[i][j]-a[i][j]-1)
ans=x[i][j]-a[i][j]-1;
}
cout<<ans;
return 0;
}
Compilation message
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:49:9: error: 'i' was not declared in this scope
49 | i=n/2;
| ^
maxcomp.cpp:63:9: error: 'i' was not declared in this scope
63 | i=n/2;
| ^