CF607A.Chain Reaction

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

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.

数轴上有 nn 个信标,各自位于互不相同的位置上。第 ii 个信标的位置为 aia_i,能量等级为 bib_i。当激活第 ii 个信标时,它会摧毁其左侧(即坐标减小的方向)距离不超过 bib_i(含端点)范围内的所有信标。但该信标自身不会被摧毁。埼玉将从右至左依次激活这些信标。若某个信标已被摧毁,则它无法再被激活。

埼玉希望杰诺斯在所有现有信标严格右侧的某个位置添加一个新信标(位置和能量等级可任选),使得被摧毁的信标总数尽可能少。注意:杰诺斯所添加的信标将作为第一个被激活的信标。请帮助杰诺斯求出可能被摧毁的信标数量的最小值。

输入格式

The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the initial number of beacons.

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.

输入的第一行包含一个整数 nn(1≤n≤100 0001 \leq n \leq 100\,000)—— 初始的信标数量。

接下来的 nn 行中,第 ii 行包含两个整数 aia_i 和 bib_i(0≤ai≤1 000 0000 \leq a_i \leq 1\,000\,000,1≤bi≤1 000 0001 \leq b_i \leq 1\,000\,000)—— 分别表示第 ii 个信标的位置和功率。任意两个信标位置均不相同,即当 i≠ji \neq j 时,有 ai≠aja_i \neq a_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 1. One way to achieve this is to place a beacon at position 9 with power level 2.

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.

对于第一个样例,被摧毁的信标最小数量为 1。一种可行方案是在位置 9 处放置一个功率等级为 2 的信标。

对于第二个样例,被摧毁的信标最小数量为 3。一种可行方案是在位置 1337 处放置一个功率等级为 42 的信标。

输入解题思路,AI测评打分。不知道怎么写?

首页