89432024-02-07 12:17:03BenedekMartonÁdám és Éva együttcpp17Accepted 50/5059ms4320 KiB
#include <iostream>
#include <queue>

using namespace std;

struct kave
{
    int k, v;
};

int main()
{
    int p, a, b;
    cin >> p >> a;
    kave asz[a];
    for(int i=0; i<a; i++)
    {
        cin >> asz[i].k >> asz[i].v;
    }
    cin >> b;
    kave bsz[b], x;
    for(int i=0; i<b; i++)
    {
        cin >> bsz[i].k >> bsz[i].v;
    }
    int i=0, j=0;
    queue<kave> q;
    while(i<a and j<b)
    {
        if(max(asz[i].k, bsz[j].k)<min(asz[i].v, bsz[j].v))
        {
            x.k=max(asz[i].k, bsz[j].k);
            x.v=min(asz[i].v, bsz[j].v);
            q.push(x);
        }
        if(asz[i].v<=bsz[j].v)
        {
            i++;
        }
        else
        {
            j++;
        }
    }
    if(i==a)
    {
        i--;
        while(j<b)
        {
            j++;
            if(max(asz[i].k, bsz[j].k)<min(asz[i].v, bsz[j].v))
            {
                x.k=max(asz[i].k, bsz[j].k);
                x.v=min(asz[i].v, bsz[j].v);
                q.push(x);
            }
        }
    }
    else if(j==b)
    {
        j--;
        while(i<a)
        {
            i++;
            if(max(asz[i].k, bsz[j].k)<min(asz[i].v, bsz[j].v))
            {
                x.k=max(asz[i].k, bsz[j].k);
                x.v=min(asz[i].v, bsz[j].v);
                q.push(x);
            }
        }
    }
    cout << q.size() << endl;
    while (!q.empty())
    {
        x=q.front();
        cout << x.k << " " << x.v << endl;;
        q.pop();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1808 KiB
2Accepted0/03ms2064 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2460 KiB
5Accepted2/23ms2772 KiB
6Accepted2/23ms2868 KiB
7Accepted2/23ms3108 KiB
8Accepted2/22ms3148 KiB
9Accepted2/23ms3156 KiB
10Accepted2/22ms3156 KiB
11Accepted2/23ms3148 KiB
12Accepted2/23ms3284 KiB
13Accepted2/23ms3364 KiB
14Accepted2/22ms3364 KiB
15Accepted2/23ms3392 KiB
16Accepted2/257ms4316 KiB
17Accepted3/357ms4316 KiB
18Accepted3/352ms4256 KiB
19Accepted4/454ms4276 KiB
20Accepted4/459ms4320 KiB
21Accepted4/457ms4300 KiB
22Accepted4/457ms4300 KiB