213632026-01-12 20:41:32hunzombiTalálkozáscpp17Accepted 55/5523ms1268 KiB
#include <bits/stdc++.h>
using namespace std;

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

    int n, m = 0;
    cin >> n;
    vector<int> start_time(100001, 0), end_time(100001, 0);
    for (int i=0; i < n; i++) {
        int u, v;
        cin >> u >> v;
        start_time[u]++;
        end_time[v]++;
        m = max(m, v);
    }

    int k = (n + 1) / 2;

    int high = 1, cnt = start_time[1];

    int ans = INT_MAX, ans_low = -1, ans_high = -1;

    for (int i=1; i <= m; i++) {
        while (cnt < k && high < m) {
            high++;
            cnt += start_time[high];
        }
        if (high - i + 1 > 0 && high - i + 1 < ans && cnt >= k) {
            ans = high - i + 1;
            ans_low = i;
            ans_high = high;
        }
        cnt -= end_time[i];
    }

    cout << ans << '\n' << ans_low << ' ' << ans_high << '\n';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/02ms1076 KiB
2Accepted0/021ms1076 KiB
3Accepted2/22ms1076 KiB
4Accepted2/22ms1268 KiB
5Accepted2/22ms1076 KiB
6Accepted2/22ms1076 KiB
7Accepted2/22ms1076 KiB
8Accepted3/32ms1076 KiB
9Accepted3/32ms1076 KiB
10Accepted3/32ms1076 KiB
11Accepted3/33ms1076 KiB
12Accepted3/34ms1076 KiB
13Accepted3/34ms1076 KiB
14Accepted3/36ms1224 KiB
15Accepted3/36ms1092 KiB
16Accepted3/36ms1228 KiB
17Accepted3/34ms1076 KiB
18Accepted3/38ms1076 KiB
19Accepted3/321ms1076 KiB
20Accepted3/319ms1076 KiB
21Accepted3/323ms1220 KiB
22Accepted3/321ms1084 KiB