This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PUT(a, b) freopen(a, "r", stdin); freopen(b, "w", stdout);
#define all(a) a.begin(), a.end()
#define answerNO {cout << "NO" << endl;}
#define answerYES {cout << "YES" << endl;}
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll mod = 1e9 + 7;
 
void solve(){
    ll n; cin >> n;
    VPL v(n);
    VPL a(n);
    rep(i, n){
        ll l, r; cin >> l >> r;
        a[i].ff = max(0ll, i - l);
        a[i].ss = min(n - 1, i + r);
        v[i].ff = a[i].ss - a[i].ff;
        v[i].ss = i;
    }
    ll ans = 0;
    vector<bool> vis(n, 0);
    vector<bool> b(n);
    sort(all(v));
    rep(i, n){
        bool ok = 1;
        replr(j, a[v[i].ss].ff, a[v[i].ss].ss){
            if(b[j] == 1){
                ok = 0;
            }
        }
        if(ok){
            //cout << v[i].ss;
            if(!vis[v[i].ss]){
                b[v[i].ss] = 1;
                replr(j, a[v[i].ss].ff, a[v[i].ss].ss){
                    vis[j] = 1;
                }
                ans++;
            }
        }
    }
    //cout << endl;
    cout << ans << "\n";
}
 
 
    
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    //PUT("traffic.in", "traffic.out");
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
/*7
0 0 0
0 0 1
1 0 2
1 0 3
2 0 4
3 0 5
2 0 6
*/
| # | 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... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |