fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. #define all(x) x.begin(),x.end()
  11. #define v(x) vector<x>
  12. #define nl '\n'
  13. #define fxd(x) fixed << setprecision(x)
  14. template<class t> using ordered_set = tree<t, null_type, less<t>, rb_tree_tag, tree_order_statistics_node_update>;
  15. template<class t> using ordered_multiset = tree<t, null_type, less_equal<t>, rb_tree_tag, tree_order_statistics_node_update>;
  16.  
  17.  
  18. bool cmp(pair<ll,ll>& a ,pair<ll,ll>& b)
  19. {
  20. if(a.first == b.first)
  21. {
  22. return (b.second > a.second);
  23. }
  24. else
  25. {
  26. return (a.first < b.first);
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  33. int s , n ; cin >> s >> n;
  34. vector<pair<ll,ll>> dragon(n);
  35. for (int i = 0; i < n; i++)
  36. {
  37. cin >> dragon[i].first >> dragon[i].second;
  38. }
  39. sort(dragon.begin(),dragon.end(),cmp);
  40.  
  41. for (int i = 0; i < n; i++)
  42. {
  43. if(s > dragon[i].first)
  44. {
  45. s+= dragon[i].second;
  46. }
  47. else
  48. {
  49. cout << "NO";
  50. return 0;
  51. }
  52. }
  53. cout << "YES";
  54. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
YES