欢迎光临散文网 会员登陆 & 注册

CF 230A - Dragons

2023-07-21 16:28 作者:您是打尖儿还是住店呢  | 我要投稿

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 xi, 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 yi.


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.


Input

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 xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it.


Output

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.

-----------------------------------

桐人陷入了他现在正在玩的 MMORPG 的某个关卡。 为了在游戏中继续前进,他必须击败生活在这一层的所有 n 条龙。 桐人与龙族的实力,是用整数来表示的。 在两个对手之间的对决中,决斗的胜负取决于他们的实力。 最初,桐人的力量为s。


如果桐人开始与第 i (1 ≤ i ≤ n) 条龙决斗,并且桐人的力量不大于龙的力量 xi,则桐人在决斗中失败并死亡。 但如果桐人的力量大于龙的力量,那么他就会击败龙并获得毅力的额外力量提升。


桐人可以以任何顺序与龙战斗。 确定他是否可以进入游戏的下一个关卡,即以一败涂地的方式击败所有龙。


输入

第一行包含两个空格分隔的整数 s 和 n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103)。 然后是 n 行:第 i 行包含空格分隔的整数 xi 和 yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — 第 i 条龙的力量和击败它的奖励。


输出

如果 Kirito 可以进入下一个级别,则在单行中打印“YES”(不带引号);如果不能,则打印“NO”(不带引号)。

--------------------------------

打怪的快乐跟AC的快乐,哪个更快乐,双倍快乐最好了。。


CF 230A - Dragons的评论 (共 条)

分享到微博请遵守国家法律