소스 검색

添加 'H.cpp'

爱玲姐姐 5 년 전
부모
커밋
3fd13586a5
1개의 변경된 파일27개의 추가작업 그리고 0개의 파일을 삭제
  1. 27 0
      H.cpp

+ 27 - 0
H.cpp

@@ -0,0 +1,27 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main() {
+    int T;
+    cin>>T;
+    while(T--) {
+        int n;
+        cin>>n;
+        vector<pair<int,int>> a(n);
+        for(int i=0; i<n; i++)cin>>a[i].first>>a[i].second;
+        sort(a.begin(),a.end(),[](pair<int,int> a,pair<int,int> b)->bool {
+            return a.second-a.first<b.second-b.first;
+        });
+        bool flag=true;
+        int tot=0;
+        for(auto p:a) {
+            if(p.first+tot<p.second) {
+                flag=false;
+                break;
+            }
+            tot+=p.first;
+        }
+        cout<<(flag?"YES":"NO")<<endl;
+    }
+ 
+    return 0;
+}