46152023-03-30 12:01:32AblablablaÁdám és Éva együttcpp17Accepted 50/5041ms5624 KiB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;

int main()
{
    /*ios::sync_with_stdio(false);
    cin.tie(0);*/

    int n, a;
    cin >> n >> a;

    vector<pii> adam(a, {0, 0});
    for(int i = 0; i < a; i++){
        cin >> adam[i].first >> adam[i].second;
        adam[i].second--;
    }

    int e;
    cin >> e;
    vector<pii> eva(e, {0, 0});
    for(int i = 0; i < e; i++){
        cin >> eva[i].first >> eva[i].second;
        eva[i].second--;
    }

    int adamInd = 0;
    int evaInd = 0;
    vector<pii> valaszok;
    while(adamInd < a && evaInd < e){
        if(adam[adamInd].first <= eva[evaInd].first && adam[adamInd].second >= eva[evaInd].first){
            valaszok.push_back(pii(eva[evaInd].first, min(eva[evaInd].second, adam[adamInd].second)+1));
            if(eva[evaInd].second < adam[adamInd].second){
                //cout << "1.1\n";
                evaInd++;
            } else{
                //cout << "1.2\n";
                adamInd++;
            }
        } else if(eva[evaInd].first <= adam[adamInd].first && eva[evaInd].second >= adam[adamInd].first){
            valaszok.push_back(pii(adam[adamInd].first, min(adam[adamInd].second, eva[evaInd].second)+1));
            if(eva[evaInd].second < adam[adamInd].second){
                evaInd++;
                //cout << "2.1\n";
            } else{
                adamInd++;
                //cout << "2.2\n";
            }
        } else if(eva[evaInd].second < adam[adamInd].first){
            evaInd++;
            //cout << "3\n";
        } else{
            adamInd++;
            //cout << "4\n";
        }
    }


    cout << valaszok.size() << "\n";
    for(pii x : valaszok){
        cout << x.first << " " << x.second << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1816 KiB
2Accepted0/03ms2080 KiB
3Accepted2/22ms2208 KiB
4Accepted2/22ms2416 KiB
5Accepted2/23ms2604 KiB
6Accepted2/22ms2688 KiB
7Accepted2/22ms2696 KiB
8Accepted2/23ms2892 KiB
9Accepted2/23ms3124 KiB
10Accepted2/22ms3344 KiB
11Accepted2/23ms3548 KiB
12Accepted2/22ms3640 KiB
13Accepted2/22ms3636 KiB
14Accepted2/22ms3660 KiB
15Accepted2/22ms3632 KiB
16Accepted2/239ms5092 KiB
17Accepted3/337ms5120 KiB
18Accepted3/335ms5176 KiB
19Accepted4/437ms5260 KiB
20Accepted4/441ms5532 KiB
21Accepted4/439ms5468 KiB
22Accepted4/437ms5624 KiB