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;
int main(void) {
int n, m;
cin >> n >> m;
vector <vector <int>> a(n, vector <int> (m, -1));
int mx = -1e9;
int mn = 1e9;
pair <int,int> mxid, mnid;
for(int i = 0; i < n; i ++) {
for(int j = 0; j < m; j ++) {
cin >> a[i][j];
/*if(g[i][j] > mx) {
mx = g[i][j];
mxid = {i, j};
}
if(g[i][j] < mn) {
mn = g[i][j];
mnid = {i, j};
}*/
}
}
// cout << mx - mn - (abs(mnid.first - mxid.first) + abs(mxid.second - mnid.second) + 1);
int ans = 1e9;
for(int i = 0; i < m; i ++) {
for(int j = i + 1; j < m; j ++) {
ans = min(ans,
*max_element(a[0].begin()+i, a[0].begin()+j+1) -
*min_element(a[0].begin()+i, a[0].begin()+j+1) - (j-i+1));
}
}
cout << ans;
return false;
}
Compilation message (stderr)
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:9:6: warning: unused variable 'mx' [-Wunused-variable]
9 | int mx = -1e9;
| ^~
maxcomp.cpp:10:6: warning: unused variable 'mn' [-Wunused-variable]
10 | int mn = 1e9;
| ^~
# | 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... |