Submission #102813

#TimeUsernameProblemLanguageResultExecution timeMemory
102813alexpetrescuGap (APIO16_gap)C++14
70 / 100
81 ms1272 KiB
#include <algorithm>

#include "gap.h"

long long findGap(int T, int N) {
    long long R = 1000000000000000000LL;
    long long e, r;
    MinMax(0, R, &e, &r);
    r -= e;
    long long dist = (r + N - 2) / (N - 1), st = e, ans = 0, val = -1;
    for (int i = 1; i < N; i++) {
        long long a, b;
        MinMax(st, st + dist, &a, &b);
        st += dist + 1;

        if (a != -1) {
            if (val != -1)
                ans = std::max(ans, a - val);
            val = b;
        }
    }

    if (N == 2)
        ans = r;

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...