fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. int32_t main()
  5. {
  6. cin.tie(0);
  7. cout.tie(0);
  8. ios::sync_with_stdio(false);
  9. int t=1;
  10. //cin>>t;
  11. while(t--)
  12. {
  13. int n,k,x,y;
  14. cin>>k>>n;
  15. vector<pair<int,int>>v;
  16. for(int i=0;i<n;i++)
  17. {
  18. cin>>x>>y;
  19. v.push_back({x,y});
  20. }
  21. sort(v.begin(),v.end());
  22. for(int i=0;i<n;i++)
  23. {
  24. if(k>v[i].first)
  25. {
  26. k+=v[i].second;
  27. }
  28. else
  29. {
  30. cout<<"NO";
  31. return 0;
  32. }
  33. }
  34. cout<<"YES";
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
NO