This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gap.h"
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
long long findGap(int T, int n)
{
ll mn, mx;
MinMax(0, 1e18, &mn, &mx);
ll gap=(mx-mn-1)/(n-1)+1;
ll l=mn, r=mx, curl=l, curr=l+gap-1, ans=gap;
//cout<<curr<<endl;
while(curr-gap<=r)
{
//cout<<curl<<' '<<curr<<" "<<ans<<endl;
MinMax(curl+1, curr, &mn, &mx);
if(mx==-1) mn=mx=curl;
else mn=curl;
if(mn!=mx and mx-mn<=gap) curl=mx, curr=curl+gap-1;
else if(mn==mx) curl=mn, curr+=gap;
else
{
MinMax(curr-gap+1, curr, &mn, &mx);
if(mn==mx) ans=max(ans, mx-curl);
else ans=max(ans, mn-curl);
curl=mx, curr=curl+gap-1;
}
}
return ans;
}
/*
11
5 7 8 100 130 190 200 201 203 1000 2004
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |