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<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
ll b[1005];
int m;
void MinMax(ll a,ll c,ll &t,ll &r){
t=-1,r=-1;
for(int i=0;i<m;i++){
if(t==-1&&b[i]>=a&&b[i]<=c)t=b[i];
if(b[i]>=a&&b[i]<=c)r=b[i];
}
}
long long cal1(int n){
ll a[n];
ll l=0,r=n-1;
ll mn=0,mx=0;
ll tl=0,tr=1e18;
while(l<=r){
MinMax(tl,tr,a[l],a[r]);
tl=a[l]+1,tr=a[r]-1;
l++,r--;
}ll rs=0;
for(int i=1;i<n;i++)rs=max(rs,a[i]-a[i-1]);
return rs;
}
ll cal2(int n){
ll mn,mx;
ll tl=0,tr=1e18;
MinMax(tl,tr,mn,mx);
ll ans = (mx-mn-1)/(n-1)+1;
ll cl=-1,cr=-1;
ll rl = mn+1,rr=mn+ans;
while(1){
MinMax(rl,rr,cl,cr);
if(cl==-1){
rl = rr+1;
rr = rr+ans;
}
else {
ans = max(ans,cl-mn);
mn=cr;
rl=rr+1;
rr=rr+ans;
if(cr==mx)break;
}
}return ans;
}
long long findGap(int T, int N)
{
if(T==1)return cal1(N);
else return cal2(N);
}
/*int main(){m=5;
b[0]=2;
b[1]=3;
b[2]=6;
b[3]=500;
b[4]=10000;
cout<<findGap(2,5);
}*/
Compilation message (stderr)
gap.cpp: In function 'long long int cal1(int)':
gap.cpp:27:8: warning: unused variable 'mn' [-Wunused-variable]
27 | ll mn=0,mx=0;
| ^~
gap.cpp:27:13: warning: unused variable 'mx' [-Wunused-variable]
27 | ll mn=0,mx=0;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |