16082022-11-28 20:44:27kicsiboglarÁdám és Éva együttcpp11Accepted 50/5041ms6472 KiB
#include <iostream>
#include <vector>
#include <deque>

#define ll long long 
#define P pair<ll,ll> 

using namespace std;

ll n, m, i, j, k, mini, maxi, a, b;

deque <P > adam, eva, res1, res2, radam, reva;
bool meet(P a, P b)
{
    if (a.first >= b.second) return false;
    if (b.first >= a.second) return false;
    return true;
}

deque <P > merge(deque<P> adam, deque<P> eva)
{
    deque<P > res;
    while (!adam.empty() && !eva.empty())
    {
        if (meet(adam[0], eva[0]))
        {
            res.push_back({ max(adam[0].first,eva[0].first),min(adam[0].second,eva[0].second) });
        }
        if (adam[0].second < eva[0].second) adam.pop_front();
        else eva.pop_front();
    }
    return res;
}
int main()
{
    cin >> k;
    cin >> n;


    for (i = 1; i <= n; ++i)
    {
        cin >> a >> b;
        adam.push_back({ a,b });
    }

    cin >> m;
    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        eva.push_back({ a,b });
    }

    deque <P > res;

    res = merge(adam, eva);

    
  
    cout << res.size() << "\n";
    for (auto& e : res) cout << e.first << " " << e.second << "\n";
}

SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1820 KiB
2Accepted0/02ms2008 KiB
3Accepted2/22ms2244 KiB
4Accepted2/22ms2416 KiB
5Accepted2/22ms2620 KiB
6Accepted2/22ms2864 KiB
7Accepted2/22ms3108 KiB
8Accepted2/22ms3288 KiB
9Accepted2/22ms3404 KiB
10Accepted2/22ms3492 KiB
11Accepted2/22ms3616 KiB
12Accepted2/22ms3676 KiB
13Accepted2/22ms3800 KiB
14Accepted2/22ms3912 KiB
15Accepted2/22ms3848 KiB
16Accepted2/239ms6180 KiB
17Accepted3/339ms6184 KiB
18Accepted3/335ms5816 KiB
19Accepted4/437ms5944 KiB
20Accepted4/441ms6352 KiB
21Accepted4/439ms6472 KiB
22Accepted4/439ms6340 KiB