結果

問題 No.1570 Blocks
ユーザー hiro71687k
提出日時 2023-03-10 20:20:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 4,102 ms
コンパイル使用メモリ 254,076 KB
最終ジャッジ日時 2025-02-11 07:31:09
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=155550555555555;
ll mod=1000000007;
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n),b(n);
    priority_queue<pair<ll,ll>>pq;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i]>> b[i];
        pq.push({-a[i]-b[i],i});
    }
    vector<ll>c;
    while (!pq.empty())
    {
        c.push_back(pq.top().second);
        pq.pop();
    }
    ll ans=0;
    for (ll i = 0; i < n; i++)
    {
        if (ans>b[c[i]])
        {
            cout << "No" << endl;
            return 0;
        }
        ans+=a[c[i]];
    }
    cout << "Yes" << endl;
}
0