H.cpp 635 B

123456789101112131415161718192021222324252627
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int T;
  5. cin>>T;
  6. while(T--) {
  7. int n;
  8. cin>>n;
  9. vector<pair<int,int>> a(n);
  10. for(int i=0; i<n; i++)cin>>a[i].first>>a[i].second;
  11. sort(a.begin(),a.end(),[](pair<int,int> a,pair<int,int> b)->bool {
  12. return a.second-a.first<b.second-b.first;
  13. });
  14. bool flag=true;
  15. int tot=0;
  16. for(auto p:a) {
  17. if(p.first+tot<p.second) {
  18. flag=false;
  19. break;
  20. }
  21. tot+=p.first;
  22. }
  23. cout<<(flag?"YES":"NO")<<endl;
  24. }
  25. return 0;
  26. }