45992023-03-30 10:51:44csaron71Ádám és Éva együttcpp17Accepted 50/5046ms5980 KiB
#include <bits/stdc++.h>

using namespace std;



int main()
{
    int n;
    cin >> n;
    int a;
    cin >> a;
    vector<pair<int, int> > v;

    for (int i=0; i<a; i++) {
        int x, y;
        cin >> x >> y;
        v.push_back({x, 1});
        v.push_back({y, -1});
    }

    int b;
    cin >> b;
    for (int i=0; i<b; i++) {
        int x, y;
        cin >> x >> y;
        v.push_back({x, 1});
        v.push_back({y, -1});
    }

    vector<pair<int, int> > veg;
    int utolso;
    int epp=0;
    sort(v.begin(), v.end());

    for (int i=0; i<v.size(); i++) {
        if (v[i].second==1) {
            epp++;
            utolso=v[i].first;
        }
        else if (epp==2) {
            veg.push_back({utolso, v[i].first});
            epp--;
        }
        else {
            epp--;
        }
    }

    cout << veg.size() << "\n";
    for (auto sz : veg) {
        cout << sz.first << " " << sz.second << "\n";
    }


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1684 KiB
2Accepted0/03ms1848 KiB
3Accepted2/23ms2088 KiB
4Accepted2/22ms2172 KiB
5Accepted2/22ms2140 KiB
6Accepted2/23ms2272 KiB
7Accepted2/23ms2356 KiB
8Accepted2/23ms2484 KiB
9Accepted2/23ms2696 KiB
10Accepted2/23ms2908 KiB
11Accepted2/23ms3116 KiB
12Accepted2/23ms3344 KiB
13Accepted2/23ms3544 KiB
14Accepted2/23ms3760 KiB
15Accepted2/23ms3840 KiB
16Accepted2/243ms5980 KiB
17Accepted3/343ms5976 KiB
18Accepted3/339ms5856 KiB
19Accepted4/441ms5864 KiB
20Accepted4/446ms5880 KiB
21Accepted4/443ms5936 KiB
22Accepted4/443ms5864 KiB