Submission #981630

#TimeUsernameProblemLanguageResultExecution timeMemory
981630ShauryaTheShepGap (APIO16_gap)C++14
0 / 100
3095 ms3108 KiB
#include <iostream>
#include <climits>
#include <vector>

// Function prototype for provided MinMax function
void MinMax(long long s, long long t, long long* mn, long long* mx);

long long findGap(int T, int N) {
    if (T != 1) {
        // Subtask 1 implementation only
        return -1;
    }

    long long globalMin, globalMax;
    MinMax(LONG_LONG_MIN, LONG_LONG_MAX, &globalMin, &globalMax);

    if (N == 1) {
        // If there is only one number, no gap exists
        return 0;
    }

    long long maxGap = 0;
    long long prevMax = globalMin;
    bool first = true;

    // Brute-force from globalMin to globalMax in larger steps
    for (long long i = globalMin; i <= globalMax; i++) {
        long long mn, mx;
        MinMax(i, i, &mn, &mx);

        if (mn != -1) { // Valid number found
            if (!first) {
                maxGap = std::max(maxGap, mn - prevMax);
            } else {
                first = false;
            }
            prevMax = mx; // Update previous max
        }
    }

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