样例都过不了,大佬求调
查看原帖
样例都过不了,大佬求调
1020566
prg_equal_depressed楼主2024/7/9 16:13
#include <iostream>
#include <algorithm>
using namespace std;
int n,b,bx,l,r,s=0x3f3f3f3f;
struct stc{
	int x,y;
}a[100005];
bool cmp(stc x1,stc x2){
	return x1.x<x2.x;
}
int main(){
	cin>>n>>b;
	for (int i=1;i<=n;i++){
		cin>>a[i].x>>a[i].y;
	}
	sort(a+1,a+1+n,cmp);a[0].x=b;
	bx=upper_bound(a+1,a+n+1,a[0],cmp)-a;
	l=bx-1;r=bx;
	while (l>0&&r<=n){
		while (l>0&&a[l].x<a[r].y-a[l].y) l--;
		if (l>0) s=min(s,max(0,a[r].y-a[l].y-a[r].x));
		r++;
	}
	l=bx-1;r=bx;
	while (l>0&&r<=n){
		while (r<=n&&a[r].x<a[r].y-a[l].y) r++;
		if (r<=n) s=min(s,max(0,a[r].y-a[l].y-a[l].x));
		l--;
	}
	if (s==0x3f3f3f3f) cout<<-1;
	else cout<<s;
	return 0;
}
2024/7/9 16:13
加载中...