蒟蒻二分求改
  • 板块灌水区
  • 楼主a_little_carrot
  • 当前回复10
  • 已保存回复10
  • 发布时间2024/4/22 11:53
  • 上次更新2024/4/22 16:54:52
查看原帖
蒟蒻二分求改
1042960
a_little_carrot楼主2024/4/22 11:53

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
ll n,m,a,b,start,l=1,mid,r=1000000000000000000/*18*/ ;
map<int,int>c ;
map<int,int>::iterator it;
bool check(int f) {
	ll cnt=0,last=start ;
	for(it=c.begin();it!=c.end();++it) {
		if(last+f<it->first)cnt++,last=it->first+f ;
		ll s=abs(last-it->second) ;
		cnt+=s/f ;
		last=cnt*s+f ;
	}
	return cnt>=n ;
}
int main() {
	scanf("%d%d",&n,&m) ;
	for(register int i=1;i<=m;++i) {
		scanf("%d%d",&a,&b) ;
		if(i==1)start=a ;
		c[a]=b ;
	}r=b ;
	while(l!=r) {
		mid=(l+r)/2 ;
		if(check(mid)) {
			l=mid ;
		}else {
			r=mid ;
		}
	}
	cout<<l ;
	return 0 ;
}

玄关

lz下午期中,关注晚点给

2024/4/22 11:53
加载中...