1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <bits/stdc++.h>
using namespace std;

vector <int> miny[300003];
pair <int, int> tab[300003];

set <int> miny2[300002];

set <set <int>> wyniki;

vector <int> sensowne[300002];

bool odw[300002];

bool okk[300002];
int n;

bool czy_inne(int x, int y){

    set <int> ns;

    for (auto m: miny2[x]) ns.insert(m);
    for (auto m: miny2[y]) ns.insert(m);

    if (ns != miny2[x] && ns != miny2[y]) return  true;

    return false; 

}

void f(int px, int x){

    miny2[px].insert(x);

    for (auto m: miny[x]){

        if (miny2[px].count(m) > 0) continue;
        f(px, m);

    }

}

int dfs(int x){

    odw[x] = true;
    int ans1 = 0;

    for (auto s: sensowne[x]){

        if (odw[s]) continue;
        if (okk[s]) continue;

        odw[s] = true;
        ans1 ++;
        ans1 += dfs(s);
        odw[s] = false;

    }

    return ans1;

}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
 
    for (int i = 0; i < n; i ++) cin >> tab[i].first >> tab[i].second;

    for (int i = 0; i < n; i ++){

        for (int j = i + 1; j < n; j ++){

            if (tab[i].first + tab[i].second >= tab[j].first) miny[i].push_back(j);
            else break;

        }
        for (int j = i - 1; j >= 0; j --){

            if (tab[i].first - tab[i].second <= tab[j].first) miny[i].push_back(j);
            else break;

        }

    }

    // for (int i = 0; i < n; i ++){

    //     cout << tab[i].first << ": ";

    //     for (auto m: miny[i]) cout << m << " ";
    //     cout << "\n";

    // }

    for (int i = 0; i < n; i ++){

        f(i, i);

        // cout << tab[i].first << ": ";
        // for (auto m: miny2[i]) cout << tab[m].first << " ";
        // cout << "\n";

    }

    int ans = 1;

    // cout << ans << "\n";

    for (int i = 0; i < n; i ++){

        bool ok = true;

        for (int j = i + 1; j < n; j ++){

            // cout << i << " " << j << "\n";

            if (miny2[i].count(j) == 0 && miny2[j].count(i) == 0) {
                
                // ans ++;//cout << i << " " << j << "\n";
                sensowne[i].push_back(j);
                // sensowne[j].push_back(i);

            }

            if (miny2[i] == miny2[j]) ok = false;

            // cout << ok << "\n";

        }

        if (ok) ans ++;
        else okk[i] = true;

    }

    // cout << ans << "\n";

    // for (int i = 0; i < n; i ++){
    //     cout << tab[i].first << ": ";    
    //     for (auto s: sensowne[i]) cout << tab[s].first << " ";
    //     cout << "\n";
    // }

    for (int i = 0; i < n; i ++) {
        if(!okk[i]) ans += dfs(i); 
    }

    cout << ans << "\n";

}