607A.md (2016B)
1 Source: https://codeforces.com/problemset/problem/607/A 2 3 A. Chain Reaction 4 5 time limit per test 6 7 2 seconds 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 There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated. 22 23 Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. 24 25 Input 26 27 The first line of input contains a single integer *n* (1 ≤ *n* ≤ 100 000) — the initial number of beacons. 28 29 The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0 ≤ *a**i* ≤ 1 000 000, 1 ≤ *b**i* ≤ 1 000 000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i* ≠ *a**j* if *i* ≠ *j*. 30 31 Output 32 33 Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. 34 35 Examples 36 37 Input 38 39 ``` 40 4 41 1 9 42 3 1 43 6 1 44 7 4 45 ``` 46 47 Output 48 49 ``` 50 1 51 ``` 52 53 Input 54 55 ``` 56 7 57 1 1 58 2 1 59 3 1 60 4 1 61 5 1 62 6 1 63 7 1 64 ``` 65 66 Output 67 68 ``` 69 3 70 ``` 71 72 Note 73 74 For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. 75 76 For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.