7722022-01-10 11:14:37kicsiboglarTalálkozáscpp11Time limit exceeded 13/55298ms10352 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long 

using namespace std;

ll n, i, a, b, k, mini=100000001, p1, p2, j;

bool compare(pair<ll, ll> a, pair<ll, ll> b)
{
    if (a.second < b.second) return true;
    if (a.second == b.second)
    {
        if (a.first <= b.first) return true;
        return false;
    }
    return false;
}

int main()
{
    cin >> n;
    vector <pair<ll, ll> > x(n + 1, { 0,0 });

    for (i = 1; i <= n; ++i) cin >> x[i].first >> x[i].second;


    sort(x.begin() + 1, x.end(), compare);



    k = (n + 1) / 2;
    pair<ll, ll> act{ 0,0 };

    for (i = 1; i <= n - k + 1; ++i)
    {
        act = { x[i].second,x[i].second };
        for (j = 1; j < k; ++j)
        {
            //act.first = min(act.first, x[i + j].second);
            act.second = max(act.second, x[i + j].first);
        }
        if (act.second - act.first + 1 < mini)
        {
            mini = act.second - act.first + 1;
            p1 = act.first;
            p2 = act.second;
        }
    }
    cout << mini << "\n" << p1 << " " << p2;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base13/55
1Accepted0/03ms1860 KiB
2Time limit exceeded0/0209ms3684 KiB
3Partially correct1/21ms3148 KiB
4Accepted2/21ms3156 KiB
5Accepted2/21ms3156 KiB
6Accepted2/21ms3164 KiB
7Wrong answer0/21ms3168 KiB
8Accepted3/31ms3176 KiB
9Accepted3/31ms3180 KiB
10Wrong answer0/31ms3188 KiB
11Wrong answer0/313ms3404 KiB
12Wrong answer0/325ms3592 KiB
13Wrong answer0/326ms3712 KiB
14Wrong answer0/393ms4080 KiB
15Wrong answer0/389ms4308 KiB
16Wrong answer0/3115ms4528 KiB
17Wrong answer0/3101ms4752 KiB
18Time limit exceeded0/3226ms5576 KiB
19Time limit exceeded0/3296ms6728 KiB
20Runtime error0/357ms10352 KiB
21Time limit exceeded0/3286ms9176 KiB
22Time limit exceeded0/3298ms9956 KiB