# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981614 | ShauryaTheShep | Gap (APIO16_gap) | C++17 | 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 <iostream>
using namespace std;
// Assuming MinMax is correctly implemented and linked
extern void MinMax(long long s, long long t, long long* mn, long long* mx);
long long findGap(int T, int N) {
if (T == 1) {
long long min_value, max_value;
// Get the overall minimum and maximum to start
MinMax(0, 1LL << 60, &min_value, &max_value); // using large number assuming range
if (min_value == -1) // No values found within the range
return 0;
// Variables to store the results of MinMax calls
long long prev_value = min_value;
long long max_gap = 0;
long long current_min, current_max;
// Checking each segment, starting from min_value to max_value
long long current_position = min_value;
while (current_position <= max_value) {
MinMax(current_position, max_value, ¤t_min, ¤t_max);
if (current_min == -1) break; // No more numbers in this segment
// Calculate the gap
if (current_min - prev_value > max_gap) {
max_gap = current_min - prev_value;
}
prev_value = current_max;
current_position = current_max + 1; // Move to the next segment
}
return max_gap;
}
return -1; // For subtask 2, to be implemented later
}
int main() {
int T = 1; // Subtask number
int N; // Number of elements, must be set appropriately
cout << "Enter the number of elements N: ";
cin >> N;
cout << "The maximum gap is: " << findGap(T, N) << endl;
return 0;
}