21562022-12-26 18:35:10bzsofiaTalálkozáscpp11Wrong answer 7/5582ms7792 KiB
//#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

//ifstream fin("be.in");

struct adat
{
    int jon, megy;
};

int i, n, j, mini, minj, tav;
priority_queue <pair <int, int>> mp;

bool comp(adat a, adat b)
{
    if (a.megy==b.megy) return a.jon<b.jon;

    return a.megy<b.megy;
}

int main()
{
    cin>>n;
    tav=n;
    int fele=n/2+n%2;
    vector <adat> x(n+1);

    for (i=1; i<=n; ++i)
    {
        cin>>x[i].jon>>x[i].megy;
    }

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

    for (i=1; i<fele; ++i)
        mp.push({x[i].jon, i});

    for (i=fele; i<=n; ++i)
    {
        mp.push({x[i].jon, i});

        while (!mp.empty() && mp.top().second<i-fele+1)
            mp.pop();

        //cout<<x[i-n/2+1].megy<<" "<<mp.top().first<<"\n";
        if (tav>mp.top().first-x[i-fele+1].megy+1)
        {
            tav=mp.top().first-x[i-fele+1].megy+1;
            mini=x[i-fele+1].megy;
            minj=mp.top().first;
        }
    }

    cout<<tav<<"\n"<<mini<<" "<<minj;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base7/55
1Accepted0/03ms1808 KiB
2Wrong answer0/082ms5580 KiB
3Wrong answer0/22ms2104 KiB
4Accepted2/22ms2308 KiB
5Accepted2/22ms2508 KiB
6Wrong answer0/22ms2720 KiB
7Wrong answer0/22ms2928 KiB
8Wrong answer0/32ms3148 KiB
9Wrong answer0/32ms3332 KiB
10Wrong answer0/32ms3448 KiB
11Wrong answer0/36ms3832 KiB
12Wrong answer0/38ms3984 KiB
13Wrong answer0/38ms4188 KiB
14Wrong answer0/316ms4696 KiB
15Wrong answer0/316ms4692 KiB
16Wrong answer0/314ms4696 KiB
17Wrong answer0/316ms4824 KiB
18Wrong answer0/325ms5048 KiB
19Wrong answer0/382ms7724 KiB
20Accepted3/371ms7588 KiB
21Wrong answer0/382ms7720 KiB
22Wrong answer0/382ms7792 KiB