ABC214E - Packing Under Range Regulations

問題

https://atcoder.jp/contests/abc214/tasks/abc214_e

略説

ボールをLについて昇順に見ていき、現時点で箱に入れられるボールをRについての昇順に入れていく

ACコード
#include <bits/stdc++.h>
using namespace std;

int T;

int main() {
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        pair<int,int> LR[N];
        for (int i=0; i<N; i++) cin >> LR[i].first >> LR[i].second;
        sort(LR, LR+N);
        priority_queue<int, vector<int>, greater<int>> Rs;
        int x = 0;
        for (int i=0; i<N; i++) {
            Rs.push(LR[i].second);
            if (i+1<N && LR[i].first==LR[i+1].first) continue;
            x = max(x, LR[i].first);
            while (!Rs.empty()) {
                int r = Rs.top();
                if (i+1<N && x>=LR[i+1].first) break;
                Rs.pop();
                if (x > r) {
                    cout << "No\n";
                    goto hell;
                }
                x++;
            }
        }
        cout << "Yes\n";
hell:;
    }
}