Advertisement
Josif_tepe

Untitled

Mar 18th, 2022
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <cstring>
  7. #include <fstream>
  8. #include <map>
  9. #include <set>
  10. using namespace std;
  11. typedef long long ll;
  12. int main() {
  13.     ios_base::sync_with_stdio(false);
  14.     int n;
  15.     cin >> n;
  16.     vector<ll> v(n);
  17.     set<ll> s;
  18.     for(int i = 0; i < n; i++) {
  19.         cin >> v[i];
  20.     }
  21.     for(int i = 0; i < n - 1; i++) {
  22.         s.insert(v[i]);
  23.     }
  24.     ll result = 1e18;
  25.     for(int i = n - 1; i > 0; i--) {
  26.         set<ll>::iterator it = s.lower_bound(v[i] + 1);
  27.         if(it != s.end()) {
  28.             result = min(result, *it - v[i]);
  29.         }
  30.         s.erase(s.lower_bound(v[i - 1]));
  31.     }
  32.     cout << result << endl;
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement