Codeforces 230A - Dragons Solution

 Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh 

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,s,i,f=0;
  6. pair<int,int>p[1009];
  7. cin>>s>>n;
  8. int x[n+9],y[n+9];
  9. for(i=0; i<n; i++)
  10. {
  11. cin>>p[i].first>>p[i].second;
  12. }
  13. sort(p,p+n);
  14. for(i=0; i<n; i++)
  15. {
  16. if(p[i].first<s)
  17. s=s+p[i].second;
  18. else
  19. {
  20. cout<<"NO"<<endl;
  21. return 0;
  22. }
  23. }
  24. cout<<"YES"<<endl;
  25. }

No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.