16762022-12-01 15:33:43kovacs.peter.18fTalálkozáscpp11Wrong answer 50/5535ms6072 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 <= 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
base50/55
1Accepted0/03ms1828 KiB
2Accepted0/035ms3516 KiB
3Wrong answer0/22ms2380 KiB
4Accepted2/22ms2576 KiB
5Accepted2/22ms2696 KiB
6Accepted2/22ms2864 KiB
7Accepted2/23ms2920 KiB
8Accepted3/32ms3148 KiB
9Accepted3/32ms3272 KiB
10Accepted3/32ms3244 KiB
11Accepted3/34ms3548 KiB
12Accepted3/34ms3784 KiB
13Accepted3/34ms3684 KiB
14Accepted3/38ms3852 KiB
15Accepted3/38ms3912 KiB
16Accepted3/38ms3908 KiB
17Accepted3/38ms3888 KiB
18Accepted3/312ms4296 KiB
19Wrong answer0/328ms5304 KiB
20Accepted3/325ms5632 KiB
21Accepted3/335ms5968 KiB
22Accepted3/335ms6072 KiB