CF1601D.Difficult Mountain

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

A group of nn alpinists has just reached the foot of the mountain. The initial difficulty of climbing this mountain can be described as an integer dd.

Each alpinist can be described by two integers ss and aa, where ss is his skill of climbing mountains and aa is his neatness.

An alpinist of skill level ss is able to climb a mountain of difficulty pp only if p≤sp \leq s. As an alpinist climbs a mountain, they affect the path and thus may change mountain difficulty. Specifically, if an alpinist of neatness aa climbs a mountain of difficulty pp the difficulty of this mountain becomes max⁡(p,a)\max(p, a).

Alpinists will climb the mountain one by one. And before the start, they wonder, what is the maximum number of alpinists who will be able to climb the mountain if they choose the right order. As you are the only person in the group who does programming, you are to answer the question.

Note that after the order is chosen, each alpinist who can climb the mountain, must climb the mountain at that time.

一群 nn 名登山者刚刚抵达山脚。这座山初始的攀登难度可用一个整数 dd 来描述。

每名登山者可用两个整数 ss 和 aa 来刻画,其中 ss 表示其登山技能水平,aa 表示其整洁度(neatness)。

技能水平为 ss 的登山者仅当山的难度 pp 满足 p≤sp \leq s 时,才能成功攀登一座难度为 pp 的山。当一名登山者攀登一座山时,其行为会影响路径,从而可能改变山的难度。具体而言,若一名整洁度为 aa 的登山者攀登了一座难度为 pp 的山,则该山的难度将变为 max⁡(p,a)\max(p, a)。

登山者将依次逐个攀登此山。在开始攀登前,他们想知道:若能恰当地安排攀登顺序,最多有多少名登山者能够成功登顶?作为队伍中唯一会编程的人,你需要回答这个问题。

注意:一旦选定攀登顺序,所有在轮到其攀登时仍能满足当前山难度条件(即当前难度 ≤\leq 其技能 ss)的登山者,都必须立即攀登该山。

输入格式

The first line contains two integers nn and dd (1≤n≤500 0001 \leq n \leq 500\,000; 0≤d≤1090 \leq d \leq 10^9) — the number of alpinists and the initial difficulty of the mountain.

Each of the next nn lines contains two integers sis_i and aia_i (0≤si,ai≤1090 \leq s_i, a_i \leq 10^9) that define the skill of climbing and the neatness of the ii-th alpinist.

第一行包含两个整数 nn 和 dd(1≤n≤500 0001 \leq n \leq 500\,000;0≤d≤1090 \leq d \leq 10^9)—— 分别表示登山者人数和山的初始难度。

接下来的 nn 行中,每行包含两个整数 sis_i 和 aia_i(0≤si,ai≤1090 \leq s_i, a_i \leq 10^9),分别表示第 ii 位登山者的攀爬技能值和整洁度。

输出格式

Print one integer equal to the maximum number of alpinists who can climb the mountain if they choose the right order to do so.

输出一个整数,表示如果登山者选择合适的攀登顺序,能够登上山顶的最大人数。

输入输出样例

  • 输入#1

    3 2
    2 6
    3 5
    5 7

    输出#1

    2
  • 输入#2

    3 3
    2 4
    6 4
    4 6

    输出#2

    2
  • 输入#3

    5 0
    1 5
    4 8
    2 7
    7 6
    3 2

    输出#3

    3

说明/提示

In the first example, alpinists 22 and 33 can climb the mountain if they go in this order. There is no other way to achieve the answer of 22.

In the second example, alpinist 11 is not able to climb because of the initial difficulty of the mountain, while alpinists 22 and 33 can go up in any order.

In the third example, the mountain can be climbed by alpinists 55, 33 and 44 in this particular order. There is no other way to achieve optimal answer.

在第一个例子中,登山者 22 和 33 若按此顺序攀登,即可登上山顶。不存在其他方式达到答案 22。

在第二个例子中,登山者 11 因山的初始难度而无法攀登,而登山者 22 和 33 可以以任意顺序登顶。

在第三个例子中,登山者 55、33 和 44 按此特定顺序可以登上山顶。不存在其他方式达到最优解。

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

首页