CF607A.Chain Reaction

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn beacons located at distinct positions on a number line. The ii -th beacon has position aia_{i} and power level bib_{i} . When the ii -th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bib_{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.

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.

输入格式

The first line of input contains a single integer nn ( 1<=n<=1000001<=n<=100000 ) — the initial number of beacons.

The ii -th of next nn lines contains two integers aia_{i} and bib_{i} ( 0<=ai<=10000000<=a_{i}<=1000000 , 1<=bi<=10000001<=b_{i}<=1000000 ) — the position and power level of the ii -th beacon respectively. No two beacons will have the same position, so aiaja_{i}≠a_{j} if iji≠j .

输出格式

Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.

输入输出样例

  • 输入#1

    4
    1 9
    3 1
    6 1
    7 4
    

    输出#1

    1
    
  • 输入#2

    7
    1 1
    2 1
    3 1
    4 1
    5 1
    6 1
    7 1
    

    输出#2

    3
    

说明/提示

For the first sample case, the minimum number of beacons destroyed is 11 . One way to achieve this is to place a beacon at position 99 with power level 22 .

For the second sample case, the minimum number of beacons destroyed is 33 . One way to achieve this is to place a beacon at position 13371337 with power level 4242 .

首页