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
#include <bits/stdc++.h>

using namespace std;

#define N 25

int n;
long long a[N], r[N];

int mask[N];

int res[1 << N];

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%lld%lld", a + i, r + i);
    }

    for(int i = 0; i < n; i++) {
        long long mn = a[i] - r[i];
        long long mx = a[i] + r[i];    

        int j = i - 1, k = i + 1;
        while((j >= 0 && a[j] >= mn) || (k < n && a[k] <= mx)) {
            if(j >= 0 && a[j] >= mn) {
                mn = min(mn, a[j] - r[j]);
                mx = max(mx, a[j] + r[j]);
                j--;
            }
    
            if(k < n && a[k] <= mx) {
                mn = min(mn, a[k] - r[k]);
                mx = max(mx, a[k] + r[k]);
                k++;
            }
        }

        mask[i] = (1 << k) - 1;
        if(j >= 0)   mask[i] ^= (1 << (j + 1)) - 1;
    }
    
    for(int i = 0; i < (1 << n); i++) {
        int now = 0;
        for(int j = 0; j < n; j++)
            if(i & (1 << j))    now |= mask[j];
        res[i] = now;
    }
    sort(res, res + (1 << n));
    
    int ans = 1;
    for(int i = 1; i < (1 << n); i++) {
        ans += (res[i - 1] < res[i]);
    }

    printf("%d\n", ans);
}