#include <bits/stdc++.h>
#include "gap.h"
#define maxn 100005
#define int64_t long long
using namespace std;
int n;
constexpr int64_t INF = 1000000000000000000LL;
int64_t a[maxn];
int64_t sub1() {
int64_t mn, mx;
int64_t L = 0, R = INF;
int l = 1, r = n;
while (l <= r) {
MinMax(L, R, &mn, &mx);
a[l] = mn;
a[r] = mx;
++l; --r;
L = mn+1;
R = mx-1;
}
int64_t ans = 0;
for (int i = 1; i < n; i++) ans = max(ans, a[i+1]-a[i]);
return ans;
}
int64_t sub2() {
int64_t mn, mx;
int64_t L = 0, R = INF;
MinMax(L, R, &mn, &mx);
int64_t LowerBound = (mx-mn-1)/(n-1)+1;
int64_t ans = LowerBound;
int64_t MIN = mn, MAX = mx;
int64_t Last = MIN;
for (int64_t s = MIN+1, e = MIN+LowerBound, i = 0; i < n; s += LowerBound, e += LowerBound, i++) {
if (e >= MAX) e = MAX-1;
if (s > e) break;
MinMax(s, e, &mn, &mx);
if (mn != -1) ans = max(ans, mn-Last), Last = mx;
}
return ans;
}
long long findGap(int T, int N) {
n = N;
if (T == 1) return sub1();
return sub2();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |