104342024-04-02 12:03:02VargusTalálkozáscpp17Time limit exceeded 0/55300ms12524 KiB
#include <iostream>
#include <queue>
#define ll long long

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector <ll> a(n + 1), b(n + 1);
    for (ll i = 1; i <= n; ++i)
    {
        cin >> a[i] >> b[i];
    }
    vector <ll> stat(b[n] + 1);

    for (ll i = 1; i <= n; ++i)
    {
        for (ll j = 1; j <= n; ++j)
        {
            if (j == i)
                ++stat[b[i]];
            else
            {
                if (b[i] >= a[j] && b[i] <= b[j])
                    ++stat[b[i]];
            }
        }
    }

    ll db, akt = 1, el = 0, veg = 99999, k = 999999;
    for (ll i = 1; i <= n; ++i)
    {
        for (ll j = i+1; j <= n; ++j)
        {
            if (b[i] < a[j])
            {
                db = 1;
                for (ll g = j + 1; g <= n; ++g)
                    if (a[j] >= a[g] && a[j] <= b[g])
                        ++db;
                
                if (db + stat[b[i]] >= n / 2 && a[j]-b[i] < k)
                {
                    el = b[i];
                    veg = a[j];
                    k = veg - el;
                }
            }
            else if (b[i] == a[j])
            {
                if (stat[b[i]] >= n / 2)
                {
                    el = b[i];
                    veg = a[j];
                }
                break;
            }
        }
    }
    cout << k + 1 << endl << el << " " << veg;

    return 0;
}
/*
6
1 5
2 3
5 9
7 8
10 15
10 18
*/
SubtaskSumTestVerdictTimeMemory
base0/55
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0300ms4724 KiB
3Wrong answer0/23ms3248 KiB
4Wrong answer0/23ms3460 KiB
5Wrong answer0/23ms3672 KiB
6Wrong answer0/24ms4040 KiB
7Wrong answer0/28ms4260 KiB
8Wrong answer0/33ms4472 KiB
9Wrong answer0/34ms4468 KiB
10Wrong answer0/38ms4520 KiB
11Time limit exceeded0/3256ms4124 KiB
12Time limit exceeded0/3275ms4412 KiB
13Time limit exceeded0/3254ms4660 KiB
14Time limit exceeded0/3248ms5056 KiB
15Time limit exceeded0/3252ms5592 KiB
16Time limit exceeded0/3273ms5792 KiB
17Time limit exceeded0/3268ms5780 KiB
18Time limit exceeded0/3277ms6904 KiB
19Time limit exceeded0/3273ms9088 KiB
20Time limit exceeded0/3268ms10196 KiB
21Time limit exceeded0/3264ms11476 KiB
22Time limit exceeded0/3277ms12524 KiB