Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: C12

Problemset: วันว่างๆ

Language: cpp

Time: 0.022 second

Submitted On: 2026-01-01 21:35:00

#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pii pair<ll,ll>
#define puii pair<ull,ull>
#define piii pair<ll,pii>
#define ll long long
#define ull unsigned long long
#define mp make_pair
 
#define mpiii(a,b,c) make_pair(a,make_pair(b,c));
// ll mod = 1000000007;

void solve(){
    int n;

    cin >> n;

    int k,start,end;
    vector<pii>v;
    
    for(int i = 0;i < n;i++){
        cin >> k;
        while(k--){
            cin >> start >> end;
            v.push_back(mp(start,end));
        }
    }
    sort(v.begin(),v.end());

    ll mx = 0;
    start = -1;
    pii now;
    int cnt = 0;
    int st = v.size();

    for(int i = 0;i < st;i++){
        now = v[i];
        if(mx < now.f){
            if(mx > 0){
                cout << mx << ' ' << now.f << ' ';
                cnt = 1;
            }
        }
        mx = max(mx,now.s);
    }

    if(cnt == 0){
        cout << -1;
    }
    
    return;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll q;
 
    // cin >> q;

    // while(q--)
        solve(); 

    return 0;
}