Codeforces 230a dragons

Source: Internet
Author: User

Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat allNDragons 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 withI-Th (1 digit ≤ secondILimit ≤ limitN) 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 increaseYI.

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 IntegersSAndN(1 digit ≤ DigitSLimit ≤ limit 104, 1 limit ≤ limitNLimit ≤ limit 103). ThenNLines follow:I-Th line contains space-separated IntegersXIAndYI(1 digit ≤ DigitXILimit ≤ limit 104, 0 limit ≤ limitYILimit ≤ limit 104)-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

TIPS: Structure sorting

Struct dragon {

Int X, Y;

Bool operator <(const dragon & RHs) const {

Return x <RHS. X;

}

} Dragon [1010];

 

Sort (Dragon, Dragon + n );

Or

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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.