Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- int n;
- cin >> n;
- ll res = LLONG_MAX;
- set<ll> st;
- for(int i = 0; i < n; i++) {
- int tip;
- cin >> tip;
- if(tip == 1) {
- ll x;
- cin >> x;
- st.insert(x);
- auto it = st.lower_bound(x);
- if(it != st.begin()) {
- it--;
- res = min(res, x - *it);
- it++;
- }
- it++;
- if(it != st.end()) {
- res = min(res, *it - x);
- }
- }
- else {
- cout << res << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement