#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define ll long long
#define pii pair<int, int>
#define maxn 1005
using namespace std;
int a[maxn][maxn], mi[maxn][maxn], ma[maxn][maxn];
int n, m;
struct segtree {
int seg[4 * maxn];
void init(int cur, int l, int r, bool oper) {
if (r <= l) return;
if (r - l == 1) {
seg[cur] = a[0][l];
return;
}
int mid = (l + r) / 2;
init(cur * 2, l, mid, oper);
init(cur * 2 + 1, mid, r, oper);
if (oper) seg[cur] = max(seg[cur * 2], seg[cur * 2 + 1]);
else seg[cur] = min(seg[cur * 2], seg[cur * 2 + 1]);
}
} s1, s2;
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
for (int i = 0;i < n;i++) {
for (int j = 0;j < m;j++) cin >> a[i][j];
}
for (int i = 0;i < m;i++) {
int cur = a[0][i], c2 = a[0][i];
for (int j = i;j < m;j++) {
cur = max(cur, a[0][j]);
ma[i][j] = cur;
c2 = min(c2, a[0][j]);
mi[i][j] = c2;
}
}
int ans = 0;
for (int i = 0;i < m;i++) {
for (int j = i;j < m;j++) {
ans = max(ans, ma[i][j] - mi[i][j] - (j - i + 1));
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8192 KB |
Output is correct |
2 |
Correct |
6 ms |
8192 KB |
Output is correct |
3 |
Correct |
6 ms |
8192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
416 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |