# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
284899 | triplem5ds | 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;
long long findGap(int T, int N)
{
long long mn, mx;
MinMax(0, 1000000000000000000, &mn, &mx);
long long d = (mx - mn + N - 3) / (N - 1);
vector<long long> v({mn, mx});
long long cur = mn + 1;
while(cur < v[1]) {
MinMax(cur, min(v[1] - 1, cur + d - 1), &mn, &mx);
cur += d;
if(mn == -1)continue;
v.push_back(mn);
v.push_back(mx);
}
sort(v.begin(),v.end());
for(int i = 1; i < v.size(); i++)
ans = max(ans, v[i] - v[i-1]);
return ans;
}