Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: erng

Problemset: วันว่างๆ

Language: cpp

Time: 0.009 second

Submitted On: 2026-03-06 00:34:02

#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll n, x, e, p[1002], ava[1002], st, s, cnt;
vector<pair<ll,ll>> ans;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>x;
        for (int j=1; j<=x; j++)
        {
            cin>>s>>e;
            p[s]++;
            p[e]--;
        }
    }
    for (int i=0; i<=1001; i++)
    {
        cnt+=p[i];
        if (st==0 && cnt==0)
        {
            s=i;
            st=1;
        }
        else if (st==1 && cnt!=0)
        {
            e=i;
            st=0;
            ans.push_back({s, e});
        }
    }
    int k=0;
    for (int i=0; i<ans.size(); i++)
    {
        if (ans[i].first==0 || ans[i].second==1001) continue;
        cout<<ans[i].first<<" "<<ans[i].second<<" ";
        k=1;
    }
    if (k==0) 
    {
        cout<<-1;
    }
}