zoukankan      html  css  js  c++  java
  • CodeForces 230A 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 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 }
  • 相关阅读:
    图论1 Tarjan算法
    codevs1380 没有上司的舞会
    阿牛的EOF牛肉串
    codevs1105 过河
    HDU5340 Three Palindromes
    AndroidStudio中安装GsonFormat插件并根据json文件生成JavaBean
    Android中五种常用对话框的使用
    AndroidStudio中更新到最新版本后仍然提示:This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot o
    AndroidStudio中下载某版本gradle速度慢,从哪里高速下载指定版本gradle
    若依微服务版怎样修改Nacos中配置文件使Url不受权限认证跳过Token验证
  • 原文地址:https://www.cnblogs.com/zzy9669/p/3855091.html
Copyright © 2011-2022 走看看