fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,s,temp1,temp2;
  7. bool b=true;
  8. cin>>s>>n;
  9. int arr1[n] ;
  10. int arr2[n] ;
  11. for (int i=0;i<n;i++)
  12. {
  13. cin>>arr1[i]>>arr2[i];
  14. }
  15. for (int i = 1; i < n; i++)
  16. {
  17. for (int j = 0; j < n-1; j++)
  18. {
  19. if (arr1[j] == arr1[j+1]&&arr2[j]<arr2[j+1])
  20. {
  21. temp2 = arr2[j];
  22. arr2[j] = arr2[j+1];
  23. arr2[j+1] = temp2;
  24. }
  25. else if (arr1[j] > arr1[j+1])
  26. {
  27. temp1 = arr1[j];
  28. arr1[j] = arr1[j+1];
  29. arr1[j+1] = temp1;
  30. temp2 = arr2[j];
  31. arr2[j] = arr2[j+1];
  32. arr2[j+1] = temp2;
  33. }
  34. }
  35. }
  36.  
  37. for (int i=0;i<n;i++)
  38. {
  39. if(s>arr1[i])s=s+arr2[i];
  40. else
  41. {
  42. b=false;
  43. break;
  44. }
  45. }
  46. if(b==true)cout<<"YES"<<endl;
  47. else cout<<"NO"<<endl;
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5428KB
stdin
10 1
100 100
stdout
NO