# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
629642 | Cyber_Wolf | 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.
//Contest: APIO 16 Problem 3
//Problem Name: Gap
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
long long findGap(int subtask, int n)
{
vector<long long> v;
lg x = 0;
long long first = 0, last = 1e18;
while(x < n)
{
long long mnm, mxm;
MinMax(first, last, &mnm, &mxm);
v.push_back(mnm);
x++;
if(mnm != mxm) v.push_back(mxm), x++;
last = mnm+1;
first = mxm-1;
if(first >= last) break;
}
long long ans = 0;
sort(v.begin(), v.end());
for(int i = 1; i < v.size(); i++) ans = max(ans, v[i]-v[i-1]);
return ans;
}