http://codeforces.com/problemset/problem/230/A

Dragons
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ≤ in) 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
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.

题意就是一个人杀龙,这个人初始力量为s,有n条龙,可以按任何顺序杀龙,杀死一条龙有力量奖励y,龙的力量为x,当这个人的力量s大于龙的力量x时才能杀死这条龙,然后他的力量增加这条龙的奖励y,即s+=y

所以直接贪心就行了。

AC代码:
#include<iostream>
#include<cstdio>
#include<algorithm> using namespace std; struct Node
{
int x,y;
}g[1010]; bool cmp(Node a, Node b)
{
return a.x < b.x;
} int main()
{
int n,s,i;
while(scanf("%d%d",&s,&n)!=EOF)
{
for(i = 0; i < n; i++)
{
scanf("%d%d",&g[i].x,&g[i].y);
}
sort(g,g+n,cmp);
for(i = 0; i < n; i++)
{
if(s > g[i].x)
{
s+=g[i].y;
}
else
{
break;
}
}
if(i == n)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
} return 0;
}

Dragons的更多相关文章

  1. Codeforces 839E Mother of Dragons【__builtin_popcount()的使用】

    E. Mother of Dragons time limit per test:2 seconds memory limit per test:256 megabytes input:standar ...

  2. 【CF839E】Mother of Dragons 折半状压

    [CF839E]Mother of Dragons 题意:给你一张n个点,m条边的无向图.你有k点能量,你可以把能量分配到任意一些点上,每个点分到的能量可以是一个非负实数.定义总能量为:对于所有边&l ...

  3. L169 Komodo dragons

    Komodo dragons live on a handful of islands in Indonesia, but their reputation has spread far and wi ...

  4. B. No Time for Dragons(贪心)

    B. No Time for Dragons time limit per test 2.0 s memory limit per test 256 MB input standard input o ...

  5. JZOJ 3487. 【NOIP2013模拟联考11】剑与魔法(dragons)

    3487. [NOIP2013模拟联考11]剑与魔法(dragons) (Standard IO) Time Limits: 1000 ms  Memory Limits: 131072 KB  De ...

  6. Codeforce 230A - Dragons (sort)

    Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defe ...

  7. sgu548 Dragons and Princesses   贪心+优先队列

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=548 题目意思: 有一个骑士,要经过n个房间,开始在第一个房间,每个房间里面有龙或者 ...

  8. SGU 548 Dragons and Princesses

    意甲冠军: n个月格儿  所有的格龙或公主的儿子  从勇士1走n  不杀  杀死有钱拿  路过公主  假设之前杀龙的数量满足公主要求就会停止行走  问  勇士想多拿钱  可是必需要满足n格子的公主  ...

  9. SPOJ 10234. Here Be Dragons

    The Triwizard Tournament's third task is to negotiate a corridor of many segments, and reach the oth ...

随机推荐

  1. jsp接收相同复合参数 request.getParameterValues()用法

    在网站中往往需要用户选择复选框,此时需要创建多个复选框让用户进行选择: <head> <meta http-equiv="Content-Type" conten ...

  2. PHP 系统常量及自定义常量

    __FILE__ 这个默认常量是 PHP 程序文件名.若引用文件 (include 或 require)则在引用文件内的该常量为引用文件名,而不是引用它的文件名. __LINE__ 这个默认常量是 P ...

  3. ANDROID_MARS学习笔记_S02_004_ExpandableListActivity

    1.main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x ...

  4. linux多线程驱动中调用udelay()对整个系统造成的影响(by liukun321咕唧咕唧)

    以前没考虑过这个问题,而且之前可能运气比较好,虽然用了udelay但也没出什么奇怪的问题,今天在 CSDN上看到了一篇关于此问题帖子,觉得很受用,再此做简要的记录和分析: 驱动开的是内核线程 跟普通进 ...

  5. 坑爹的libxml2 for mingw 编译

    按照官方的readerme.txt说法生成Makefile之后,你会发现编译时候需要创建几个文件夹. 还有就是因为宏定义问题,报错,需要在config.h中加入#define HAVE_STDINT_ ...

  6. bzoj2039

    还是同一类最小割问题 对于只要记住,建图是来最小化损失, 最大化收益是所有收益-最小取不到的收益 首先对于每个经理i,如果不取,必然有signma(w[i,j])收益会得不到(这里我们先不考虑额外的损 ...

  7. apache开源项目--CouchDB

    Apache CouchDB 是一个面向文档的数据库管理系统.它提供以 JSON 作为数据格式的 REST 接口来对其进行操作,并可以通过视图来操纵文档的组织和呈现. CouchDB 是 Apache ...

  8. web移动开发最佳实践之html篇

    一.前言 在目前的移动应用开发大潮下,使用web技术进行移动应用开发正变得越来越流行,它主要使用html5.css3.js等技术,在跨平台性.可移植性方面具有无可比拟的优势,特别适合开发对性能要求不太 ...

  9. Bootstrap基本使用[转]

    Bootstrap是Twitter推出的一个由动态CSS语言Less写成的开源CSS/HTML框架(同时提供Sass 移植版代码).Bootstrap提供了全面的基本及组件样式并自带了13个jQuer ...

  10. Bootstrap之表格checkbox复选框全选 [转]

    转自: http://blog.csdn.net/shangmingchao/article/details/49761315 效果图: HTML中无需添加额外的一列来表示复选框,而是由JS完成,所以 ...