A8718 | Dragons
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $x_{i}$ , 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 $y_{i}$ .
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.
If Kirito starts duelling with the $i$ -th ( $1<=i<=n$ ) dragon and Kirito's strength is not greater than the dragon's strength $x_{i}$ , 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 $y_{i}$ .
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<=10^{4}$ , $1<=n<=10^{3}$ ). Then $n$ lines follow: the $i$ -th line contains space-separated integers $x_{i}$ and $y_{i}$ ( $1<=x_{i}<=10^{4}$ , $0<=y_{i}<=10^{4}$ ) — 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.
输入输出样例
输入 #1
2 2 1 99 100 0
输出 #1
YES
输入 #2
10 1 100 100
输出 #2
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.
In the second sample Kirito's strength is too small to defeat the only dragon and win.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted