fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define F first
  4. #define S second
  5. using namespace std;
  6.  
  7.  
  8. //bool compare(const pair<int,int> &a,const pair<int,int> &b)
  9. //{
  10. // if(a.F == b.F){
  11. // return a.S > b.S;//decrease
  12. // }
  13. // return a.F < b.F;//increase
  14. //}
  15. int main(){
  16. int n;
  17. ll s;
  18. cin>>s>>n;
  19. vector<pair<int,int>>v(n);
  20. for(int i=0;i<n;i++){
  21. cin>>v[i].first>>v[i].second;
  22. }
  23. sort(v.begin(),v.end());
  24.  
  25. for(int i=0;i<n;i++){
  26. if(v[i].first<s){
  27. s+=v[i].second;
  28. }else{
  29. cout<<"NO"<<endl;
  30. return 0;
  31. }
  32. }
  33. cout<<"YES"<<endl;
  34. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
YES