Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Few500

Problemset: วันว่างๆ

Language: cpp

Time: 0.015 second

Submitted On: 2026-03-21 15:56:43

#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    map<int, int> mp;
    while (n--)
    {
        int m;
        cin >> m;
        while (m--)
        {
            int start, end;
            cin >> start >> end;
            mp[start]++;
            mp[end]--;
        }
    }

    vector<int> ans;
    int sum = 0;
    for (auto x : mp)
    {
        if (ans.size() % 2 == 1)
            ans.push_back(x.first);
        sum += x.second;
        if (sum == 0)
            ans.push_back(x.first);
    }

    if (ans.size() == 1)
        cout << "-1\n";
    for (int i = 0; i < ans.size() - 1; i++)
        cout << ans[i] << ' ';
    return 0;
}