Advertisement
Josif_tepe

Untitled

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