#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> suf_max(n + 2);
vector<int> suf_min(n + 2, 1e18);
int ans = 1e18;
for(int i = n; i > 0; i--) {
suf_max[i] = max(suf_max[i + 1], a[i]);
suf_min[i] = min(suf_min[i + 1], a[i]);
}
for(int i = n - 1; i > 0; i--) {
ans = min(ans, suf_max[i] - suf_min[i]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
9 ms |
3420 KB |
Output isn't correct |
6 |
Incorrect |
9 ms |
3420 KB |
Output isn't correct |
7 |
Incorrect |
11 ms |
3340 KB |
Output isn't correct |