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.

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 <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int N=;
const int mod=1e9+;
struct Node
{
int x, y;
}a[N];
bool cmp(Node i,Node j)
{
return i.x<j.x;
}
int main()
{
int s,n;
scanf("%d %d",&s,&n);
for(int i=;i<n;i++){
scanf("%d %d",&a[i].x,&a[i].y);
}
sort(a,a+n,cmp);
int flag=;
for(int i=;i<n;i++){
if(a[i].x>=s){
flag=;
break;
}
else{
s+=a[i].y;
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}

Codeforce 230A - Dragons (sort)的更多相关文章

  1. JS中的算法与数据结构——排序(Sort)(转)

    排序算法(Sort) 引言 我们平时对计算机中存储的数据执行的两种最常见的操作就是排序和查找,对于计算机的排序和查找的研究,自计算机诞生以来就没有停止过.如今又是大数据,云计算的时代,对数据的排序和查 ...

  2. JS中的算法与数据结构——排序(Sort)

    排序算法(Sort) 引言 我们平时对计算机中存储的数据执行的两种最常见的操作就是排序和查找,对于计算机的排序和查找的研究,自计算机诞生以来就没有停止过.如今又是大数据,云计算的时代,对数据的排序和查 ...

  3. 【阿里巴巴Java开发手册——集合处理】13.集合的稳定性(order)和有序性(sort)

    有序性(sort):指遍历的结果是按照某种比较规则依次排列的. 稳定性(order):指集合每次遍历的元素的次序是一定的. 如:ArrayList是order/unsort HashMap是unord ...

  4. MongoDB入门---文档查询之$type操作符&limit方法&skip方法&简单排序(sort)操作

    上一篇文章呢,已经分享过了一部分查询操作了,这篇文章呢?就来继续分享哈.接下来呢我们直接看MongoDB中的$type操作符哈.它呢是基于BSON类型来检索集合中匹配的数据类型,并且返回结果,在Mon ...

  5. BZOJ3990 排序(sort)

    排序(sort) 题目描述 小A有一个1~2N的排列A[1..2N],他希望将数组A从小到大排序.小A可以执行的操作有N种,每种操作最多可以执行一次.对于所有的i(1<=i<=N),第i种 ...

  6. 洛谷P1654 产品排序(sort)

    P1654 产品排序(sort) 题目描述 有一系列产品,给定每个产品的加工时间和冷却成型时间(冷却过程产品之间没有关系,是单独冷却的).现在你手上有两台机器可以用来加工,你需要安排产品加工的顺序以及 ...

  7. 结构体快排回顾(sort)

    一般来说,我做竞赛的时候排序一般用快排 很快很方便 普通sort(从小到大) sort(a,a+n); 直接贴一段代码吧,包含了vector,sort,结构体等简单东西综合 #include < ...

  8. Python:如何排序(sort)

    一.前言 对Python的列表(list)有两个用于排序的方法: 一个是内建方法list.sort(),可以直接改变列表的内容: >>> list1 = [9,8,7,6,5] &g ...

  9. 对排序(Sort)的研究

    这一篇主要是介绍一些数据排序的基本算法和高级算法并利用JavaScript来逐一实现, 算法的说明: 稳定:如果a原本在b前面,当a=b时,排序之后a仍然在b的前面 不稳定:如果a原本在b的前面,当a ...

随机推荐

  1. Java数据结构--单链表

    #java学习经验总结------单链表的建立与结点的增删 在该链表结点有data数据,并且还有cpu,分给cpu随机的时间片,根据时间片大小进行结点data的排序 链表结点的建立 class Lin ...

  2. cookie的设置与取值

    设置cookie function cookie(key, value, options) { let days let time let result // A key and value were ...

  3. pycharm的这些配置,你都知道吗

    前言 对于一枚pycharm工具的使用新手,正确了解这门工具的配置,在使用过程中遇到的很多问题也可以迎刃而解哦!! 文章篇幅有限,本篇文章提供以下配置手段: 1.字体大小调整 2.显示你需要的工具窗口 ...

  4. Percona Xtrabackup 备份工具

    生成备份 $ xtrabackup --backup --target-dir=/data/backups/ 注:--target-dir可以放在my.cnf配置文件中.如果指定的目录不存在,xtra ...

  5. JavaSE学习笔记(13)---线程池、Lambda表达式

    JavaSE学习笔记(13)---线程池.Lambda表达式 1.等待唤醒机制 线程间通信 概念:多个线程在处理同一个资源,但是处理的动作(线程的任务)却不相同. 比如:线程A用来生成包子的,线程B用 ...

  6. HTML5基础-新增标签+新增属性+布局案例

    html5中常用的结构标签 article 文章 header 头部 nav 导航 section 区域 aside 侧边栏 hgroup 区块的相关信息 figure 定义一组内容及标题 figca ...

  7. 腾讯云nginx配置https

    给腾讯nginx服务器配置https, 之前申请https配置后直接给node配置了,还没有用nginx. 按照 https://cloud.tencent.com/document/product/ ...

  8. mysql - 拼接多个字段

    方法介绍 concat_ws(分隔符,需要拼接在一起的字段) 实例 SELECT day_catering.S_ID, day_catering.S_DAY_WEEKS_CAPTION, concat ...

  9. dubbo的使用

    dubbo现在用的也不多,基本都在用spring cloud那一套,所以不详细写这个dubbo了. 1.zookeeper的安装 2.demo示例 我们需要把提供者注册到dubbo注册中心,消费者去订 ...

  10. install multiple versions of CUDA

    https://www.pugetsystems.com/labs/hpc/How-To-Install-CUDA-10-together-with-9-2-on-Ubuntu-18-04-with- ...