46712023-03-30 20:19:14Erik_GepardÁdám és Éva együttcpp17Accepted 50/5023ms8032 KiB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define int long long

void solve(){
    int p;
    cin>>p;
    int n, m;
    cin>>n;
    vector<pii> a; //second: 1 ha jött, -1 ha ment, first: timestamp
    for(int i=0; i<n; i++){
        int b, c;
        cin>>b>>c;
        a.pb(mp(b, 1));
        a.pb(mp(c, -1));
    }
    cin>>m;
    for(int i=0; i<m; i++){
        int b, c;
        cin>>b>>c;
        a.pb(mp(b, 1));
        a.pb(mp(c, -1));
    }
    sort(a.begin(), a.end());
    int cnt=0;
    vector<pii> ans;
    for(int i=0; i<a.size(); i++){
        cnt+=a[i].se;
        if(cnt==2){
            ans.pb(mp(a[i].fi, a[i+1].fi));
        }
    }
    cout<<ans.size()<<"\n";
    for(pii x : ans) cout<<x.fi<<" "<<x.se<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/03ms2032 KiB
3Accepted2/23ms2364 KiB
4Accepted2/23ms2384 KiB
5Accepted2/23ms2488 KiB
6Accepted2/22ms2560 KiB
7Accepted2/22ms2460 KiB
8Accepted2/23ms2592 KiB
9Accepted2/23ms2948 KiB
10Accepted2/23ms3040 KiB
11Accepted2/23ms3252 KiB
12Accepted2/23ms3352 KiB
13Accepted2/22ms3332 KiB
14Accepted2/22ms3324 KiB
15Accepted2/23ms3412 KiB
16Accepted2/220ms7772 KiB
17Accepted3/320ms7984 KiB
18Accepted3/319ms7876 KiB
19Accepted4/420ms7908 KiB
20Accepted4/423ms8032 KiB
21Accepted4/420ms8016 KiB
22Accepted4/420ms8004 KiB