This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 5e5 + 5;
int n, x, y, L[NMAX], ans;
vector<pair<int, int>> v;
stack<pair<int, int>> st;
int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n;
    for(int i = 0; i < n; i++) cin >> x >> y, v.emplace_back(x, y);
    sort(all(v));
    for(int i = 0; i < n; i++){
        auto&[x, y] = v[i];
        while(st.size() && y - st.top().second >= x - st.top().first) st.pop();
        st.emplace(x, y);
        L[i] = st.size();
    }
    while(st.size()) st.pop();
    ans = 1e9;
    for(int i = n - 1; i >= 0; i--){
        auto&[x, y] = v[i];
        if(st.size() && st.top().first == x) continue;
        while(st.size() && y - st.top().second >= st.top().first - x) st.pop();
        st.emplace(x, y);
        ans = min(ans, L[i] + (int) st.size() - 1);
    }
    cout << ans;
    return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:19:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |         auto&[x, y] = v[i];
      |              ^
Main.cpp:27:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |         auto&[x, y] = v[i];
      |              ^| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |