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;
ll findGap(int T, int n){
if(T == 1){
ll arr[100100];
ll i=0, j=n-1;
ll minval=0, maxval=1000000000000000000;
while(i<j){
MinMax(minval, maxval, &minval, &maxval);
arr[i++]=minval++;
arr[j--]=maxval--;
}
if(i == j){
MinMax(minval, maxval, &minval, &maxval);
arr[i]=minval;
}
ll diff=0;
for(int j=1; j<n; ++j) diff = max(diff, arr[j]-arr[j-1]);
return diff;
}
else {
ll first=0, last=1000000000000000000;
MinMax(first, last, &first, &last);
ll l = last - first - 1;
ll mod = l % n;
ll diff = l/n;
ll start = first + 1;
ll a, b;
ll latest = first;
for(int i=0; i<mod; ++i){
MinMax(start, start + l/n + (mod != 0) - 1, &a, &b);
if(a >= 0){
diff = max(diff, a - latest);
latest = b;
}
start = start + l/n + (mod != 0);
}
for(int i=mod; i<n; ++i){
MinMax(start, start + l/n - 1, &a, &b);
if(a >= 0){
diff = max(diff, a - latest);
latest = b;
}
start+=l/n;
}
return diff;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |