首页 > 其他 > 详细

CodeForces 230A Dragons

时间:2014-07-19 22:20:05      阅读:396      评论:0      收藏:0      [点我收藏+]

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.

Sample test(s)
input
2 2
1 99
100 0
output
YES
input
10 1
100 100
output
NO

小技巧:结构体排序

struct Dragon{

    int x,y;

    bool operator < (const Dragon &rhs) const{

        return x < rhs.x;

    }

}dragon[1010];

 

sort(dragon,dragon+n);

或者

int cmp(Dragon a,Dragon b){

    return a.x < b.x;

}

 

sort(dragon,dragon+n,cmp);

 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 const int maxn = 1010;
 5 struct Dragon{
 6     int x,y;
 7     bool operator < (const Dragon &rhs) const{
 8         return x < rhs.x;
 9      }
10 }dragon[1010];
11  
12 int main(){
13     int s,n;
14     scanf("%d%d",&s,&n);
15     for(int i = 0;i < n;i++){
16         scanf("%d%d",&dragon[i].x,&dragon[i].y);
17     }
18     sort(dragon,dragon+n);
19     bool flag = 1;
20     for(int i = 0;i < n;i++){
21         if(s <= dragon[i].x){
22             flag = 0;
23             break;
24         }else{
25             s += dragon[i].y;
26         }
27     }
28     if(flag)    puts("YES");
29     else        puts("NO");
30     return 0;
31 }

 

CodeForces 230A Dragons,布布扣,bubuko.com

CodeForces 230A Dragons

原文:http://www.cnblogs.com/zzy9669/p/3855091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!