15A.md (1723B)
1 Source: https://codeforces.com/problemset/problem/15/A 2 3 A. Cottage Village 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 64 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. 22 23 The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. 24 25 Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? 26 27 Input 28 29 The first line of the input data contains numbers *n* and *t* (1 ≤ *n*, *t* ≤ 1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side ( - 1000 ≤ *x**i* ≤ 1000, 1 ≤ *a**i* ≤ 1000). 30 31 Output 32 33 Output the amount of possible positions of the new house. 34 35 Examples 36 37 Input 38 39 ``` 40 2 2 41 0 4 42 6 2 43 ``` 44 45 Output 46 47 ``` 48 4 49 ``` 50 51 Input 52 53 ``` 54 2 2 55 0 4 56 5 2 57 ``` 58 59 Output 60 61 ``` 62 3 63 ``` 64 65 Input 66 67 ``` 68 2 3 69 0 4 70 5 2 71 ``` 72 73 Output 74 75 ``` 76 2 77 ``` 78 79 Note 80 81 It is possible for the *x*-coordinate of the new house to have non-integer value.