CodeForces 230 A. Dragons

来源:互联网 发布:根域名中国镜像服务器 编辑:程序博客网 时间:2024/05/21 20:21

A. Dragons

 

Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat alln 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 equalss.

If Kirito starts duelling with the i-th (1 ≤ i ≤ n) dragon and Kirito's strength is not greater than the dragon's strengthxi, 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 byyi.

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). Thenn lines follow: the i-th line contains space-separated integersxi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — thei-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.

Examples

Input

2 2
1 99
100 0

Output

YES

Input

10 1
100 100

Output

NO

Note

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.

#include<stdio.h>

#include<algorithm>

using namespace std;

struct hanshu

{

    double a;

    double b;

}c[10000];

int cmp(struct hanshu q,struct hanshu w)

{

    return q.a<w.a;

}

int main()

{

    int m,n,i;

    scanf("%d%d",&m,&n);

    int flag=0;

    for(i=0;i<n;i++)

    {

        scanf("%lf%lf",&c[i].a,&c[i].b);

    }

    sort(c,c+n,cmp);

    for(i=0;i<n;i++)

    {

        if(m>c[i].a)

        {

            m=m+c[i].b;

        }

        else

        {

            flag=1;

            break;

        }

    }

    if(flag==0)

        printf("YES\n");

    else

        printf("NO\n");

    return 0;

}

 

 

百度翻译:

Kirito是停留在一个水平的游戏他玩了。要继续在游戏中,他必须击败所有N龙生活在这个水平。Kirito和小龙是有力量的,这是由一个整数表示。在两个对手的决斗中,决斗的结果取决于他们的实力。最初,Kirito的实力等于S.

如果Kirito开始决斗的第i(1 ≤ 我 ≤ n)龙、Kirito强度不大于龙的力量西,然后Kirito输了决斗和死亡。但如果Kirito的强度大于龙的力量,然后他战胜龙得到奖金强度提高一。

Kirito可以以任何顺序战龙。确定他是否可以继续到下一级的游戏,也就是说,击败所有的龙没有一个单一的损失。

输入

一行包含两个整数N、S(1 ≤ 的 ≤ 104、1 ≤ N ≤ 103)。接下来的N行:第i行包含整数xi和yi(1 ≤ 西 ≤ 104、0 ≤ 一 ≤ 104)-打败它的第i个龙的力量和奖金。

输出

“一行打印”(没有引号),如果Kirito可以进入下一个级别,打印“不”(不带引号),如果他不能。

在第一个样品的强度先等于2 Kirito。作为第一个龙的强度小于2,Kirito可以战胜它,战胜它。之后,他得到的奖金和他的力量增加到2 + 99 = 101。现在他可以击败第二龙,并继续到下一级。

第二样Kirito的力量太小,失败的唯一龙赢。

原创粉丝点击