Dragons
http://codeforces.com/problemset/problem/230/A
2 seconds
256 megabytes
standard input
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 ≤ 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.
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.
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.
2 2
1 99
100 0
YES
10 1
100 100
NO
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
#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的更多相关文章
- 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 ...
- 【CF839E】Mother of Dragons 折半状压
[CF839E]Mother of Dragons 题意:给你一张n个点,m条边的无向图.你有k点能量,你可以把能量分配到任意一些点上,每个点分到的能量可以是一个非负实数.定义总能量为:对于所有边&l ...
- L169 Komodo dragons
Komodo dragons live on a handful of islands in Indonesia, but their reputation has spread far and wi ...
- 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 ...
- JZOJ 3487. 【NOIP2013模拟联考11】剑与魔法(dragons)
3487. [NOIP2013模拟联考11]剑与魔法(dragons) (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB De ...
- 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 ...
- sgu548 Dragons and Princesses 贪心+优先队列
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=548 题目意思: 有一个骑士,要经过n个房间,开始在第一个房间,每个房间里面有龙或者 ...
- SGU 548 Dragons and Princesses
意甲冠军: n个月格儿 所有的格龙或公主的儿子 从勇士1走n 不杀 杀死有钱拿 路过公主 假设之前杀龙的数量满足公主要求就会停止行走 问 勇士想多拿钱 可是必需要满足n格子的公主 ...
- SPOJ 10234. Here Be Dragons
The Triwizard Tournament's third task is to negotiate a corridor of many segments, and reach the oth ...
随机推荐
- 如何设置、查看以及调试core文件
http://blog.csdn.net/xiaoxiaoniaoer1/article/details/7740820 1.core文件的生成开关和大小限制--------------------- ...
- cocos2d-x for js 继承的写法
cocos2d-x for js中集成了两套继承写法,一套是JR的(jquery的作者),一套是google. 目前来说,cocos2d-x for js demo使用JR的写法----未完待续... ...
- 将手机micro USB口转换为USB type C连接器的低成本方案
我们知道USB IF提出的type C连接器的终极目标是统一各种USB 接口. 尽管USB 3.0在PC市场上发展的风生水起,但是由于USB 3.0对手机4G LTE的EMI和RFI干扰,导致市场上除 ...
- Android开发UI之个性化控件之Menu
MenuDrawer 滑出式菜单,通过拖动屏幕边缘滑出菜单,支持屏幕上下左右划出,支持当前View处于上下层,支持Windows边缘.ListView边缘.ViewPager变化划出菜单等. 项目地址 ...
- [Hadoop源码解读](六)MapReduce篇之MapTask类
MapTask类继承于Task类,它最主要的方法就是run(),用来执行这个Map任务. run()首先设置一个TaskReporter并启动,然后调用JobConf的getUseNewAPI()判断 ...
- Linux kernel AACRAID Driver Compat IOCTL 本地安全绕过漏洞
漏洞名称: Linux kernel AACRAID Driver Compat IOCTL 本地安全绕过漏洞 CNNVD编号: CNNVD-201311-390 发布时间: 2013-11-29 更 ...
- 常用的Web服务器
常用的Web服务器有IIS.Apache.Tomcat.Jboss.Resin.Weblogic.WebSpher IISIIS服务是Windows产品自带的一种免费的Web服务器,安装配置简单,主要 ...
- ASP.NET MVC3学习心得-----表单和HTML辅助方法
5.1表单的使用 5.1.1 action和method的特性 表单是包含输入元素的容器,包含按钮.复选框.文本框等元素,表单的这些输入元素使得用户能够向页面中输入信息,并把输入信息提交给服务器.A ...
- ruby编程语言-学习笔记5(第5章 语句和控制结构)
以下是2种表达方式一样. if expression code end if expression then #推荐这种形式 code end expression的值不是false或nil,则cod ...
- hunnu---11547 你的组合数学学得如何?
解析:比较简单的DP,从左向右一个一个连续着放,dp[X][Y]表示到第X个硬币的时候Y状态的方案数,Y=0表示x左边那个不是正面的,Y=1表示x左边那个是正面 如果左边不是正面,那么当前放正面的就把 ...