# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585285 | Do_you_copy | 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 <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
const ll Mod = 1000000007;
const int maxN = 1e5 + 1;
const ll inf = LLONG_MAX;
int n;
ll a[maxN];
ll findGap(int T, long int N){
if (T & 1){
ll mn, mx;
MinMax(0, inf, &mn, &mx);
a[1] = mn, a[N] = mx;
for (int i = 2; i <= (N + 1) / 2; ++i){
MinMax(mn + 1, mx - 1, &mn, &mx);
a[i] = mn, a[N - i + 1] = mx;
}
ll ans = 0;
for (int i = 2; i <= N; ++i){
ans = max(ans, a[i] - a[i - 1]);
}
return ans;
}
else{
ll mn, mx;
MinMax(0, inf, &mn, &mx);
ll ans = 0, i = mn, last = LLONG_MAX;
int j = (mx - mn) / (N - 1);
for (; i <= mx; i += j){
ll x, y;
MinMax(i, i + j, &x, &y);
ans = max(ans, x - last);
last = y;
}
return ans;
}
}