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 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 21 99100 0

output

YES

input

10 1100 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.

题解:不多说 水水

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 using namespace std;
13 #define lowbit(x) (x&(-x))
14 #define max(x,y) (x>y?x:y)
15 #define min(x,y) (x<y?x:y)
16 #define MAX 100000000000000000
17 #define MOD 1000000007
18 #define pi acos(-1.0)
19 #define ei exp(1)
20 #define PI 3.141592653589793238462
21 #define INF 0x3f3f3f3f3f
22 #define mem(a) (memset(a,0,sizeof(a)))
23 typedef long long ll;
24 const int N=1005;
25 const int mod=1e9+7;
26 struct Node
27 {
28     int x, y;
29 }a[N];
30 bool cmp(Node i,Node j)
31 {
32     return i.x<j.x;
33 }
34 int main()
35 {
36     int s,n;
37     scanf("%d %d",&s,&n);
38     for(int i=0;i<n;i++){
39         scanf("%d %d",&a[i].x,&a[i].y);
40     }
41     sort(a,a+n,cmp);
42     int flag=1;
43     for(int i=0;i<n;i++){
44         if(a[i].x>=s){
45             flag=0;
46             break;
47         }
48         else{
49             s+=a[i].y;
50         }
51     }
52     if(flag) cout<<"YES"<<endl;
53     else cout<<"NO"<<endl;
54     return 0;
55 }

时间: 2024-10-10 14:48:50

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

洛谷P1654 产品排序(sort)

P1654 产品排序(sort) 题目描述 有一系列产品,给定每个产品的加工时间和冷却成型时间(冷却过程产品之间没有关系,是单独冷却的).现在你手上有两台机器可以用来加工,你需要安排产品加工的顺序以及去哪台机器加工,使得所有产品都成型的时间最早.机器之间互不相关,可以同时进行工作,一个机器一个时刻只能加工一个产品. 输入输出格式 输入格式: 第一行一个数n,表示产品个数,以下n行,每行两个数分别表示产品加工的时间A[i]和冷却时间B[i]. [数据规模] 对于20%的数据,满足n≤6: 对于10

结构体快排回顾(sort)

一般来说,我做竞赛的时候排序一般用快排 很快很方便 普通sort(从小到大) sort(a,a+n); 直接贴一段代码吧,包含了vector,sort,结构体等简单东西综合 #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef struct example { int elem1; int elem2; }example; /*这个compariso

Python:如何排序(sort)

一.前言 Python的列表(list)有两个排序方法: 一种是内建的list.sort()方法,可以直接改变列表的内容: >>> list1 = [9,8,7,6,5] >>> list1.sort() >>> list1 [5, 6, 7, 8, 9] 另一个内建函数是sorted(),它的特点是不改变原列表的内容,而是根据一个可迭代对象建立一个新的列表: >>> list2 = [4,3,2,1] >>> li

排序(sort)

1.定义 排序 所谓排序,就是要整理文件中的记录,使之按关键字递增(或递减)次序排列起来.其确切定义如下: 输入:n个记录R1,R2,…,Rn,其相应的关键字分别为K1,K2,…,Kn. 输出:Ril,Ri2,…,Rin,使得Ki1≤Ki2≤…≤Kin,或Ki1≥Ki2≥…≥Kin. 记录 被排序的对象--文件由一组记录组成. 记录则由若干个数据项(或域)组成.其中有一项可用来标识一个记录,称为关键字项.该数据项的值称为关键字(Key). 注意: 在不易产生混淆时,将关键字项简称为关键字. 关键

codeforce 906 SOL (A)

一道英语阅读理解,满满的都是套路,欺负我英文不好(自己去翻译吧,我就不写中文了) 原题链接 我们模拟一遍就好了,如果"!"把句子中没出现的字母排除,"."就排除句子里出现的. 注意答案是从已知那个字母开始统计的. #include<bits/stdc++.h> using namespace std; int n,len,p[28],ot[28],ed,ans,top; char ch[37],s[100007]; int main () { freop

stl实现结构体排序关键语法要点(sort)

sort函数,调用时使用函数头: #include <algorithm> sort(begin,end);用来表示一个范围. 1 int _tmain(int argc, _TCHAR* argv[]) 2 { 3 int a[20]={2,4,1,23,5,76,0,43,24,65},i; 4 for(i=0;i<20;i++) 5 cout<<a[i]<<endl; 6 sort(a,a+20); 7 for(i=0;i<20;i++) 8 cout

杭电 2803 The MAX(sort)

Description Giving N integers, V1, V2,,,,Vn, you should find the biggest value of F.  Input Each test case contains a single integer N (1<=N<=100). The next line contains N integers, meaning the value of V1, V2....Vn.(1<= Vi <=10^8).The input

codeforce 906 SOL (B)

题目大意:老师要排座位,要求每个人的四周的邻居不是原来的,求方案 题目链接 SOL :min(n,m)<4 就暴搜,否则就构造. #include<bits/stdc++.h> using namespace std; #define N 500017 int n,m,p[N],dx[4] = {0,1,0,-1},dy[4]={1,0,-1,0}; bool check(int i, int j){ int x=(i-1)/m+1,y=(i-1)%m+1,x2=(j-1)/m+1,y2

Hadoop阅读笔记(四)——一幅图看透MapReduce机制

时至今日,已然看到第十章,似乎越是焦躁什么时候能翻完这本圣经的时候也让自己变得更加浮躁,想想后面还有一半的行程没走,我觉得这样“有口无心”的学习方式是不奏效的,或者是收效甚微的.如果有幸能有大牛路过,请指教如何能以效率较高的方式学习Hadoop. 我已经记不清圣经<hadoop 实战2>在我手中停留了多久,但是每一页每一章的翻过去,还是在脑壳里留下了点什么. 一段时间以来,我还是通过这本书加深以及纠正了我对于MapReduce.HDFS乃至Hadoop的新的认识.本篇主要介绍MapReduce