This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct cell
{
int x;
int i, j;
};
bool comp (cell a, cell b)
{
if (a.x == b.x)
{
if (a.i == b.i)
return a.j < b.j;
return a.i < b.i;
}
return a.x < b.x;
}
cell a[1000001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int N = 0;
for (int i=1; i<=n; i++)
{
for (int j=1; j<=m; j++)
{
int x;
cin >> x;
N++;
a[N].x = x;
a[N].i = i, a[N].j = j;
}
}
sort (a+1, a+N+1, comp);
int ans = -1;
for (int i=1; i<N; i++)
{
for (int j=N; j>i; j--)
{
int d = abs(a[i].i - a[j].i) + abs(a[i].j - a[j].j) + 1;
int s = a[j].x - a[i].x - d;
ans = max(ans, s);
}
}
cout << ans;
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... |