213582026-01-12 20:22:18hunzombiTalálkozáscpp17Wrong answer 51/5528ms1588 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();
            if (low <= high) {
                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
base51/55
1Accepted0/01ms316 KiB
2Accepted0/028ms1588 KiB
3Wrong answer0/21ms500 KiB
4Accepted2/21ms500 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted3/31ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/33ms656 KiB
12Accepted3/34ms504 KiB
13Accepted3/33ms508 KiB
14Accepted3/36ms564 KiB
15Accepted3/36ms564 KiB
16Accepted3/34ms564 KiB
17Accepted3/34ms576 KiB
18Accepted3/38ms564 KiB
19Partially correct1/324ms1480 KiB
20Accepted3/324ms1580 KiB
21Accepted3/328ms1472 KiB
22Accepted3/328ms1480 KiB