#include "bits/stdc++.h"
using namespace std;
#define int long long
int sol(vector <vector <int>> a) {
int n = a.size() - 1;
int m = a[0].size() - 1;
int ans = -1;
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
for (int x = i; x <= n; x ++) {
for (int y = j; y <= m; y ++) {
ans = max(ans, abs(a[i][j] - a[x][y]) - abs(i - x) - abs(j - y) - 1);
}
}
}
}
return ans;
}
signed main() {
int n, m;
cin >> n >> m;
vector <vector <int>> a(n + 1, vector <int> (m + 1));
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) cin >> a[i][j];
}
int ans = sol(a);
for (int i = 1; i <= n; i ++) {
reverse(a[i].begin() + 1, a[i].end());
// for (int j : a[i]) cout << j << ' ';
// cout << endl;
}
ans = max(ans, sol(a));
cout << ans << endl;
return 0;
}
# | 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... |