16932022-12-01 15:50:25kovacs.peter.18fTalálkozáscpp11Accepted 55/5534ms5820 KiB
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> arriveS(N), leaveS(N);
    for (int i = 0; i < N; i++) {
        cin >> arriveS[i] >> leaveS[i];
    }
    sort(arriveS.begin(), arriveS.end());
    sort(leaveS.begin(), leaveS.end());
    int min_begin = -1, min_end, count = 0, a_index = 0, l_index = 0;
    for (int l = 0, r = 0; l <= 100000; l++) {
        // r: időintervallum vége (nyílt)
        while (r == l || r <= 100000 && count * 2 < N) {
            while (a_index < N && arriveS[a_index] == r) {
                ++a_index;
                ++count;
            }
            ++r;
        }
        // l: időintervallum eleje (zárt)
        if (count * 2 >= N && (min_begin == -1 || min_end - min_begin > r - l)) {
            min_begin = l;
            min_end = r;
        }
        while (l_index < N && leaveS[l_index] == l) {
            ++l_index;
            --count;
        }
    }
    cout << min_end - min_begin << '\n' << min_begin << " " << min_end - 1 << '\n';
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1832 KiB
2Accepted0/034ms3484 KiB
3Accepted2/23ms2348 KiB
4Accepted2/23ms2432 KiB
5Accepted2/22ms2648 KiB
6Accepted2/22ms2720 KiB
7Accepted2/23ms2852 KiB
8Accepted3/32ms2912 KiB
9Accepted3/33ms3036 KiB
10Accepted3/33ms3244 KiB
11Accepted3/34ms3644 KiB
12Accepted3/34ms3620 KiB
13Accepted3/34ms3876 KiB
14Accepted3/38ms4012 KiB
15Accepted3/38ms4140 KiB
16Accepted3/38ms4212 KiB
17Accepted3/38ms4220 KiB
18Accepted3/312ms4468 KiB
19Accepted3/327ms5492 KiB
20Accepted3/324ms5748 KiB
21Accepted3/334ms5700 KiB
22Accepted3/332ms5820 KiB