#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll inf = 2000000000;
int main() {
ll n, m;
cin >> n >> m;
vector<vector<int>>matrica(n, vector<int>(m));
ll maks = 0;
ll najdi, najdj;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
cin >> matrica[i][j];
if (maks < (abs(matrica[i][j] - matrica[0][0]) - i - j - 1)) {
maks = abs(matrica[i][j] - matrica[0][0]) - i - j - 1;
najdi = i;
najdj = j;
}
}
}
// cout << najdi << " " << najdj << endl;
ll maks2 = 0;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
maks2 = max(maks2, abs(matrica[i][j] - matrica[najdi][najdj]) - abs(najdi - i) - abs(j - najdj) - 1);
}
}
cout << maks2 << endl;
}
| # | 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... |