#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |