# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
300090 | a_player | Gap (APIO16_gap) | C++14 | 0 ms | 0 KiB |
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>
using namespace std;
typedef long long ll;
long long findGap(int T, int N){
if(T==1){
ll mx, mn;
vector<ll> a(N);
MinMax(0,2e18,&mn,&mx);
a[0]=mn;
a[N-1]=mx;
int i=1;
while(mx!=mn){
MinMax(mn+1,mx-1,&mn,&mx);
if(mn==-1)break;
a[i]=mn;
a[N-i-1]=mx;
i++;
}
ll ans=0;
for(int i=1;i<N;i++)ans=max(ans,a[i]-a[i-1]);
cout<<ans;
return 0;
}
ll mn,mx;
MinMax(0,2e18,&mn,&mx);
ll d=(mx-mn+N-1)/N;
ll a=mn+1;
ll b=mn+d;
ll l=mn;
ll ans=0;
for(int i=0;i<N;i++){
if(b>=mx)b=mx-1;
if(s>e)break;
ll mnn,mxx;
MinMax(a,b,&mnn,&mxx);
if(mnn!=-1){
ans=max(ans,mnn-l);
l=mxx;
}
a+=d;
b+=d;
}
ans=max(ans,mx-l);
cout<<ans;
return 0;
}