CF230A.Dragons

普及/提高-

通过率:0%

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 nn 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 ss .

If Kirito starts duelling with the ii -th ( 1<=i<=n1<=i<=n ) dragon and Kirito's strength is not greater than the dragon's strength xix_{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 yiy_{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.

输入格式

The first line contains two space-separated integers ss and nn ( 1<=s<=1041<=s<=10^{4} , 1<=n<=1031<=n<=10^{3} ). Then nn lines follow: the ii -th line contains space-separated integers xix_{i} and yiy_{i} ( 1<=xi<=1041<=x_{i}<=10^{4} , 0<=yi<=1040<=y_{i}<=10^{4} ) — the ii -th dragon's strength and the bonus for defeating it.

输出格式

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.

输入输出样例

  • 输入#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=1012+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.

首页