26542023-01-18 12:06:18kicsiboglarTalálkozáscpp11Wrong answer 43/55279ms13420 KiB
#include <iostream>
//#include <fstream>
#include <vector>
#include <deque>
#include <algorithm>
#include <climits>
#include <map>
#define ll long long 

using namespace std;
//ifstream cin ("input.in");
//ofstream cout ("output.out");

ll n,m,i,j,a,b,len,start,nr,pos,mini=LLONG_MAX,curr;

struct adat
{
    ll value,nr;
    bool st;
};

bool compare (const adat& a, const adat &b)
{
    if (a.value<b.value) return true;
    if (a.value==b.value) return a.st;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin>>n;
    vector <adat> x(2*n+1);
    for (i=1;i<=n;++i)
    {
        cin>>a>>b;
        x[2*i-1].value=a;
        x[2*i-1].nr=i;
        x[2*i-1].st=true;
        x[2*i].value=b;
        x[2*i].nr=i;
        x[2*i].st=false;
        
    }

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

    start=1;
    a=1;
    curr=2;
    while (a<n/2&&curr<=2*n)
    {
        if (x[curr].st) a++;
        curr++;
    }
    pos=1;
    mini=x[curr-1].value-x[start].value;
    while (curr<=2*n)
    {
        if (x[curr].st) a++;
        while (start<=curr&&a>n/2)
        {
            if (!x[start].st) a--;
            start++;
        }
        while (a==n/2) 
        {
            if (!x[start].st) break;
            start++;
        }
        if (a>=n/2&&x[curr].value-x[start].value+1<mini)
        {
            mini=x[curr].value-x[start].value+1;
            pos=x[start].value;
        }
        curr++;
    }

    

    cout<<mini<<"\n"<<pos<<" "<<pos+mini-1;

}
SubtaskSumTestVerdictTimeMemory
base43/55
1Accepted0/03ms1832 KiB
2Accepted0/054ms11312 KiB
3Wrong answer0/22ms2228 KiB
4Wrong answer0/22ms2344 KiB
5Wrong answer0/22ms2500 KiB
6Accepted2/22ms2512 KiB
7Accepted2/22ms2744 KiB
8Accepted3/32ms2836 KiB
9Accepted3/32ms3052 KiB
10Accepted3/32ms3260 KiB
11Accepted3/34ms3740 KiB
12Accepted3/36ms4360 KiB
13Accepted3/36ms4316 KiB
14Accepted3/39ms5244 KiB
15Accepted3/39ms5552 KiB
16Accepted3/39ms5280 KiB
17Accepted3/39ms5416 KiB
18Accepted3/316ms6800 KiB
19Wrong answer0/343ms13296 KiB
20Time limit exceeded0/3279ms7984 KiB
21Accepted3/356ms13292 KiB
22Accepted3/356ms13420 KiB