CF230A.Dragons

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals s.

If Kirito starts duelling with the i-th (1 ≤ i ≤ n) dragon and Kirito's strength is not greater than the dragon's strength x__i, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by y__i.

Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss.

桐人被困在了他正在玩的这款大型多人在线角色扮演游戏(MMORPG)的某一层。为了进入游戏的下一层,他必须击败生活在该层的全部 nn 条龙。桐人和每条龙都具有一个以整数表示的“力量值”。在双方对决中,胜负由各自的力量值决定。初始时,桐人的力量值为 ss。

若桐人与第 ii 条龙(1≤i≤n1 \le i \le n)展开对决,且桐人的力量值不大于该龙的力量值 xix_i,则桐人战败并死亡;但若桐人的力量值严格大于该龙的力量值,则桐人获胜,并获得力量值奖励 yiy_i。

桐人可以按任意顺序与各条龙战斗。请判断他是否能够成功进入游戏的下一层——即,在不战败一次的前提下击败所有龙。

输入格式

The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers x__i and y__i (1 ≤ x__i ≤ 104, 0 ≤ y__i ≤ 104) — the i-th dragon's strength and the bonus for defeating it.

第一行包含两个用空格分隔的整数 ss 和 nn(1 ≤ s ≤ 1041 \le s \le 10^4,1 ≤ n ≤ 1031 \le n \le 10^3)。接下来是 nn 行:第 ii 行包含两个用空格分隔的整数 xix_i 和 yiy_i(1 ≤ xi ≤ 1041 \le x_i \le 10^4,0 ≤ yi ≤ 1040 \le y_i \le 10^4)——分别表示第 ii 条龙的力量值和击败它所获得的奖励。

输出格式

On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.

在一行中输出 "YES"(不带引号),如果基里托能够进入下一级;否则输出 "NO"(不带引号)。

输入输出样例

  • 输入#1

    2 2
    1 99
    100 0

    输出#1

    YES
  • 输入#2

    10 1
    100 100

    输出#2

    NO

说明/提示

In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.

In the second sample Kirito's strength is too small to defeat the only dragon and win.

在第一个样例中,桐人的初始力量值为 2。由于第一条龙的力量值小于 2,桐人可以与之战斗并将其击败。之后他获得奖励,力量值提升至 2+99=1012 + 99 = 101。现在他可以击败第二条龙,并进入下一层。

在第二个样例中,桐人的力量值过小,无法击败唯一的龙并获胜。

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

首页