3 solutions

  • -1
    @ 2026-5-27 17:07:58
    #define int long long
    #define endl '\n'
    using namespace std;
    int n,a[1000000];
    bool check(int x){
    	int i=0,u=0;
    	while(i<n&&u<3){
    		int l=a[i]+2ll*x;
    		u++;
    		while(i<n&&a[i]<=l)i++;
    	}
    	return i==n;
    }
    signed main(){
    	ios::sync_with_stdio(0);
    	cin.tie(0),cout.tie(0);
    	cin>>n;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
    	}
    	sort(a,a+n);
    	int l=0,r=a[n-1]-a[0];
    	while(l<r){
    		int mid=(l+r)/2;
    		if(check(mid)){
    			r=mid;
    		}else{
    			l=mid+1;
    		}
    	}
    	cout<<l<<endl;
    	return 0;
    }
    
    
    

    Information

    ID
    1595
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    (None)
    # Submissions
    47
    Accepted
    10
    Uploaded By