Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <cstring>
- #include <fstream>
- #include <map>
- #include <set>
- using namespace std;
- typedef long long ll;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<ll> v(n);
- set<ll> s;
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- for(int i = 0; i < n - 1; i++) {
- s.insert(v[i]);
- }
- ll result = 1e18;
- for(int i = n - 1; i > 0; i--) {
- set<ll>::iterator it = s.lower_bound(v[i] + 1);
- if(it != s.end()) {
- result = min(result, *it - v[i]);
- }
- s.erase(s.lower_bound(v[i - 1]));
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement