213572026-01-12 20:18:59hunzombiTalálkozáscpp17Wrong answer 50/5530ms1588 KiB
#include <bits/stdc++.h>
using namespace std;

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

    int n;
    cin >> n;
    vector<pair<int, int>> vec(n);
    for (int i=0; i < n; i++) cin >> vec[i].first >> vec[i].second;

    int k = (n + 1) / 2;

    priority_queue<int, vector<int>, greater<int>> pq;

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

    for (int i=0; i <  n; i++) {
        pq.push(vec[i].second);
        if ((int)pq.size() > k) {
            pq.pop();
        }
        if ((int)pq.size() == k) {
            int high = vec[i].first;
            int low = pq.top();
            int dist = high - low + 1;
            if (dist < ans) {
                ans = dist;
                ans_low = low;
                ans_high = high;
            }
        }
    }

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

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/55
1Accepted0/01ms316 KiB
2Accepted0/030ms1588 KiB
3Wrong answer0/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted3/31ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms560 KiB
11Accepted3/32ms316 KiB
12Accepted3/33ms316 KiB
13Accepted3/33ms548 KiB
14Accepted3/36ms564 KiB
15Accepted3/36ms588 KiB
16Accepted3/36ms748 KiB
17Accepted3/36ms572 KiB
18Accepted3/38ms676 KiB
19Wrong answer0/326ms1480 KiB
20Accepted3/326ms1476 KiB
21Accepted3/329ms1480 KiB
22Accepted3/329ms1536 KiB