41272023-03-15 11:02:23horvathabelÁdám és Éva együttcpp17Runtime error 26/5032ms63168 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int p,a;
	cin>>p>>a;
	vector<int> ad;
	ad.assign(p+1, 0);
	int mx=0;
	for (int i=0; i<a;i++){
		int x,y;
		cin>>x>>y; 
		ad[x]=1; 
		ad[y]=-1;
		mx=max(mx, y);
	} 
	int e;
	cin>>e;
	vector<int> ev;
	ev.assign(p+1, 0);
	for (int i=0; i<e;i++){
		int x,y;
		cin>>x>>y;
		
		ev[x]=1;
		ev[y]=-1;
		mx=max(mx,y);
	}
	vector<pair<int,int>> ans; 
	bool adi=false, evi=false;  
	for (int i=0; i<mx;i++){
		if (ad[i]==1) adi=true;
		if (ad[i]==-1) adi=false;
		if (ev[i]==1) evi=true;
		if (ev[i]==-1) evi=false;
		
		if(adi && evi){
			int k=i,v;
			while (ev[i]!=-1 && ad[i]!=-1 && i<mx){
				i++;
			}
			v=i;
			i--;
			ans.push_back({k,v});
		}
	}
	cout<<ans.size()<<endl;
	for (auto ins:ans) cout<<ins.first<<" "<<ins.second<<endl;
}
SubtaskSumTestVerdictTimeMemory
base26/50
1Accepted0/03ms1808 KiB
2Accepted0/04ms3412 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2460 KiB
5Accepted2/23ms2700 KiB
6Accepted2/23ms2884 KiB
7Accepted2/23ms3064 KiB
8Accepted2/23ms3148 KiB
9Accepted2/23ms3148 KiB
10Accepted2/23ms3284 KiB
11Accepted2/23ms3436 KiB
12Accepted2/23ms4192 KiB
13Accepted2/24ms4932 KiB
14Accepted2/24ms4912 KiB
15Accepted2/26ms11412 KiB
16Runtime error0/228ms63168 KiB
17Runtime error0/332ms62928 KiB
18Runtime error0/327ms62684 KiB
19Runtime error0/427ms62656 KiB
20Runtime error0/432ms62652 KiB
21Runtime error0/427ms62628 KiB
22Runtime error0/427ms62600 KiB