比赛 USACO银组复现(ION ONLINE模拟赛) 评测结果 AAAAAAAAAA
题目名称 Social Distancing 最终得分 100
用户昵称 夜莺 运行时间 0.439 s
代码语言 C++ 内存使用 5.92 MiB
提交时间 2020-04-05 17:10:51
显示代码纯文本
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXM=100005;
struct note{
	long long left;
	long long right;
}grass[MAXM];
bool cmp(const note a,const note b){return a.left<b.left;}
long long n,m;
inline bool pd(long long d){
	long long last=grass[1].left,now=1;
	for(int i=2;i<=n;i++){
		if(last+d<=grass[now].right)
			last+=d;
		else{
			while(last+d>grass[now].right&&now<m)
				now++;
			if(last+d>grass[now].right)return 0;
			last=last+d>=grass[now].left?last+d:grass[now].left;
		}
	}
	return 1;
}
int main(){
	freopen("usaco_20Open_socdist.in","r",stdin);
	freopen("usaco_20Open_socdist.out","w",stdout);
	scanf("%lld%lld",&n,&m);
	for(long long i=1;i<=m;i++)
		scanf("%lld%lld",&grass[i].left,&grass[i].right);
	sort(grass+1,grass+1+m,cmp);
	long long l=0,r=grass[m].right;
	while(l<r){
		long long mid=(l+r)/2+1;
		if(pd(mid))l=mid;
		else r=mid-1;
	}
	printf("%lld",l);
	return 0;
}