3422021-10-15 12:15:26rmlanÁdám és Éva közül legalább az egyikcpp14Accepted 40/4071ms7500 KiB
#include<bits/stdc++.h>
using namespace std;

bool comp(int a, int b){
    if(abs(a) == abs(b)){
        return a < b;
    }
    return abs(a) < abs(b);
}

int main(){

    int p,a,e;
    cin >> p >>a;
    vector<int> idop;
    for(int i = 0; i< a; i++){
        int ai,bi;
        cin >> ai >> bi;
        idop.push_back(ai);
        idop.push_back(-1*bi-1);
    }
    cin >> e;
    for(int i = 0; i < e; i++){
        int ai,bi;
        cin >> ai >> bi;
        idop.push_back(ai);
        idop.push_back(-1*bi-1);
    }
    int m=0;
    vector<pair<int, int> > ans;
    sort(idop.begin(), idop.end(),comp);
    pair<int, int> me;
    for(int i = 0; i < idop.size(); i++){

        if(idop[i] > 0) m++;
        if(idop[i] < 0) m--;
        if(m > 0 && me.first == 0){
            me.first = idop[i];

        }
        if(m == 0 && idop[i] < 0){
            me.second = -1*(idop[i]+1);
            ans.push_back(me);
            me.first=0;
            me.second=0;
        }

    }cout << ans.size() << endl;
    for(int i = 0; i< ans.size(); i++){
        cout << ans[i].first << " " << ans[i].second <<endl;
    }
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1748 KiB
2Accepted0/02ms1824 KiB
3Accepted2/21ms1884 KiB
4Accepted2/21ms1888 KiB
5Accepted2/21ms1900 KiB
6Accepted2/21ms1900 KiB
7Accepted2/21ms1908 KiB
8Accepted2/21ms1912 KiB
9Accepted2/21ms1912 KiB
10Accepted2/21ms1916 KiB
11Accepted2/21ms1916 KiB
12Accepted2/21ms1928 KiB
13Accepted2/21ms1928 KiB
14Accepted2/21ms1940 KiB
15Accepted2/21ms1932 KiB
16Accepted2/271ms3712 KiB
17Accepted2/261ms4348 KiB
18Accepted2/254ms4860 KiB
19Accepted2/257ms5476 KiB
20Accepted2/268ms6468 KiB
21Accepted2/263ms6860 KiB
22Accepted2/261ms7500 KiB