Codeforce 230A - Dragons (sort)
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 }