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;
const int INF = 2e9;
struct STree {
int n;
vector<int> st;
STree(int _n) : n(_n), st(2 * n, -INF) {}
void update(int p, int val) {
p += n;
if (st[p] < val) {
st[p] = val;
while (p /= 2) {
st[p] = max(st[2 * p], st[2 * p + 1]);
}
}
}
int query(int l, int r) {
int res = -INF;
for (l += n, r += n; l < r; l /= 2, r /= 2) {
if (l & 1) res = max(res, st[l++]);
if (r & 1) res = max(st[--r], res);
}
return res;
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
STree sum(m), sub(m);
int ans = -INF;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
sum.update(j, a[i][j] + i + j);
sub.update(j, -a[i][j] + i + j);
ans = max({ans, sum.query(0, j + 1) - i - j - a[i][j] - 1, a[i][j] - i - j + sub.query(0, j + 1) - 1});
}
}
cout << ans << '\n';
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... |