545C.md (2148B)
1 Source: https://codeforces.com/problemset/problem/545/C 2 3 C. Woodcutters 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. 22 23 There are *n* trees located along the road at points with coordinates *x*1, *x*2, ..., *x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i* - *h**i*, *x**i*] or [*x**i*;*x**i* + *h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. 24 25 Input 26 27 The first line contains integer *n* (1 ≤ *n* ≤ 105) — the number of trees. 28 29 Next *n* lines contain pairs of integers *x**i*, *h**i* (1 ≤ *x**i*, *h**i* ≤ 109) — the coordinate and the height of the *і*-th tree. 30 31 The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. 32 33 Output 34 35 Print a single number — the maximum number of trees that you can cut down by the given rules. 36 37 Examples 38 39 Input 40 41 ``` 42 5 43 1 2 44 2 1 45 5 10 46 10 9 47 19 1 48 ``` 49 50 Output 51 52 ``` 53 3 54 ``` 55 56 Input 57 58 ``` 59 5 60 1 2 61 2 1 62 5 10 63 10 9 64 20 1 65 ``` 66 67 Output 68 69 ``` 70 4 71 ``` 72 73 Note 74 75 In the first sample you can fell the trees like that: 76 77 * fell the 1-st tree to the left — now it occupies segment [ - 1;1] 78 * fell the 2-nd tree to the right — now it occupies segment [2;3] 79 * leave the 3-rd tree — it occupies point 5 80 * leave the 4-th tree — it occupies point 10 81 * fell the 5-th tree to the right — now it occupies segment [19;20] 82 83 In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].