제출 #1140066

#제출 시각아이디문제언어결과실행 시간메모리
1140066argon1Swimming competition (LMIO18_plaukimo_varzybos)C++20
10 / 100
247 ms4328 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000000;
int times[MAX_N+5];
int N, A, B;

bool isFeasible(int maxDiff) {
    int groupStart = 0;  // Indexul de început al grupului curent

    for (int i = 0; i < N; ++i) {
        // Dacă diferența dintre cel mai lent și cel mai rapid depășește maxDiff sau grupul devine prea mare (> B), încheiem grupul curent
        if (times[i] - times[groupStart] > maxDiff || i - groupStart + 1 > B) {
            // Verificăm dacă grupul format are o dimensiune validă
            if (i - groupStart < A) return false;
            // Începem un nou grup
            groupStart = i;
        }
    }

    // Verificăm dacă ultimul grup este valid
    if (N - groupStart < A) return false;

    return true;
}

int main() {

    cin >> N >> A >> B;

    for (int i = 0; i < N; ++i) {
        cin >> times[i];
    }

    //Sort
    sort(times, times + N);

    //Binary search for the minimum maximum difference
    int low = 0;
    int high = times[N - 1] - times[0];
    int result = high;

    while (low <= high) {
        int mid = low + (high - low) / 2;

        // Check if this mid value is feasible
        if (isFeasible(mid)) {
            result = mid; // Update result and try for a smaller maximum difference
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }

    cout << result << "\n";

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