41262023-03-15 11:01:28horvathabelÁdám és Éva együttcpp17Runtime error 26/5032ms62440 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++;
			}
			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/03ms3408 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2480 KiB
5Accepted2/23ms2696 KiB
6Accepted2/23ms2868 KiB
7Accepted2/23ms3080 KiB
8Accepted2/23ms3296 KiB
9Accepted2/23ms3372 KiB
10Accepted2/23ms3516 KiB
11Accepted2/23ms3664 KiB
12Accepted2/23ms4420 KiB
13Accepted2/24ms5284 KiB
14Accepted2/24ms5516 KiB
15Accepted2/26ms11940 KiB
16Runtime error0/232ms62440 KiB
17Runtime error0/332ms62412 KiB
18Runtime error0/330ms62304 KiB
19Runtime error0/430ms62280 KiB
20Runtime error0/430ms62124 KiB
21Runtime error0/432ms62116 KiB
22Runtime error0/432ms62108 KiB