16062022-11-28 20:37:59kicsiboglarTalálkozáscpp11Time limit exceeded 13/55300ms6740 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/03ms1816 KiB
2Time limit exceeded0/0300ms2872 KiB
3Partially correct1/22ms2224 KiB
4Accepted2/22ms2420 KiB
5Accepted2/22ms2548 KiB
6Accepted2/22ms2492 KiB
7Wrong answer0/22ms2516 KiB
8Accepted3/32ms2588 KiB
9Accepted3/32ms2708 KiB
10Wrong answer0/32ms2592 KiB
11Wrong answer0/314ms3044 KiB
12Wrong answer0/328ms3364 KiB
13Wrong answer0/328ms3348 KiB
14Wrong answer0/394ms3452 KiB
15Wrong answer0/396ms3700 KiB
16Wrong answer0/387ms3648 KiB
17Wrong answer0/392ms3648 KiB
18Time limit exceeded0/3239ms4300 KiB
19Time limit exceeded0/3259ms4360 KiB
20Runtime error0/361ms6740 KiB
21Time limit exceeded0/3264ms4292 KiB
22Time limit exceeded0/3261ms4376 KiB