#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define pip pair<int, pii>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#ifdef TOAD
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#else
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#endif // TOAD
const ll maxn = 1e3+5;
const int iinf = 1e9+5;
int n, m;
int arr[maxn][maxn];
vector<int> dx = {1, 1, -1, -1};
vector<int> dy = {-1, 1, -1, 1};
signed main(){
IOS();
cin>>n>>m;
int ans = -1;
vector<pip> pus;
REP(i, n){
REP(j, m){
cin>>arr[i][j];
pus.pb({arr[i][j], {i, j}});
}
}
sort(ALL(pus));
vector<int> mn(4);
REP(i, 4) mn[i] = iinf;
REP(i, SZ(pus)){
int pp = pus[i].f;
REP(j, i){
ans = max(ans, pp-pus[j].f - abs(pus[i].s.f - pus[j].s.f) - abs(pus[i].s.s - pus[j].s.s) - 1);
}
}
cout<<ans<<endl;
}
/*
2 3
2 4 3
5 7 5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |