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
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int mod = 1e9 + 7;
long long wyn = 0;
int n, a, r;
vector <pair <int, long long>> miny; 
int ile[300007];
vector <int>list[300007];
bool roz[300000];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n; 

    miny.push_back({ -1,-1 });
	for (int i = 0; i < n; i++)
	{
		cin >> a >> r; 
		miny.push_back({ a,r });
        ile[a] = 1;
	}
    miny.push_back({ -1,-1 });

    int range = 0, newrange = 0, i = 1, dod = 0;
    while (i <= n)
    {
        newrange = miny[i].first + miny[i].second;
        if (newrange > range)
            range = newrange; 

        list[miny[i].first].push_back(miny[i].first);
        for (int j = i; j <= n; j++)
        {
            if (miny[j + 1].first <= range && miny[j + 1].first != -1)
            {
                ile[miny[i].first]++;
                list[miny[i].first].push_back(miny[j+1].first);
                newrange = miny[j + 1].first + miny[j + 1].second;
                if (newrange > range)
                    range = newrange;
            }

            else
            {
                range = 0;
                break;
            }
        }
        i++;
    }
   
    i--;
    range = 1000000;
   
    while (i >= 1)
    {
        newrange = miny[i].first - miny[i].second;
        if (newrange < range)
            range = newrange;

        for (int j = i; j >= 1; j--)
        {
            if (miny[j - 1].first >= range && miny[j-1].first != -1)
            {
                ile[miny[i].first]++;
                list[miny[i].first].push_back(miny[j-1].first);
                newrange = miny[j - 1].first - miny[j - 1].second;
                if (newrange < range)
                    range = newrange;
            }

            else
            {
                range = 10000000;
                break;
            }
        }
        i--;
    }
   

    for (auto i : miny)
    {           
        if (list[i.first].size() != 0 && roz[list[i.first].size()] == 0)
        {
            wyn++;
            roz[list[i.first].size()] = 1;
        }
        //for (auto e : list[i.first])
        //{
        //    cout << e << " ";
        //}
        //cout << endl << endl;

    }
    
    cout << wyn + n;
    return 0;
}