CodeForces 785B Anton and Classes

简单判断。

找第一类区间中$R$最大的,以及第二类区间中$L$最小的,判断距离。

找第二类区间中$R$最大的,以及第一类区间中$L$最小的,判断距离。

两种情况取个最大值即可。

#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;

int n,m;
int a,b,c,d;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		if(i==1) a=y; else a = min(a,y);
		if(i==1) c=x; else c = max(c,x);
	}

	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		if(i==1) b=x; else b = max(b,x);
		if(i==1) d=y; else d = min(d,y);
	}

	printf("%d\n",max(max(b-a,0),max(c-d,0)));
	return 0;
}
posted @ 2017-05-17 18:25  Fighting_Heart  阅读(185)  评论(0编辑  收藏  举报