Advertisement
maycod23

practise_contest_2_q_2

Mar 6th, 2022
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int s, n; cin >> s >> n;
  6.     vector<pair<int, int>> v(n);
  7.     for (int i = 0; i < n; i++)
  8.     {
  9.         cin >> v[i].first >> v[i].second;//xi and yi
  10.     }
  11.     //goal is to defeat the all the dragons
  12.     //strategy->kill the dragon with low strength first
  13.     sort(v.begin(), v.end());
  14.     bool flag = true;
  15.     for (int i = 0; i < n; i++)
  16.     {
  17.         if (s > v[i].first)
  18.         {
  19.             s += v[i].second;
  20.         }
  21.         else
  22.         {
  23.             flag = false; break;
  24.         }
  25.     }
  26.  
  27.     if (flag) cout << "YES" << endl;
  28.     else cout << "NO" << endl;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement