26522023-01-18 11:41:01kicsiboglarTalálkozáscpp11Wrong answer 43/5550ms13312 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)
    {
        return a.value<b.value;
    }

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 (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/03ms2012 KiB
2Accepted0/050ms11408 KiB
3Wrong answer0/22ms2384 KiB
4Wrong answer0/22ms2408 KiB
5Wrong answer0/22ms2636 KiB
6Accepted2/22ms2828 KiB
7Accepted2/22ms3032 KiB
8Accepted3/32ms3240 KiB
9Accepted3/32ms3440 KiB
10Accepted3/32ms3516 KiB
11Accepted3/34ms3776 KiB
12Accepted3/36ms4488 KiB
13Accepted3/36ms4384 KiB
14Accepted3/39ms5232 KiB
15Accepted3/39ms5700 KiB
16Accepted3/38ms5384 KiB
17Accepted3/39ms5384 KiB
18Accepted3/314ms6812 KiB
19Wrong answer0/339ms13184 KiB
20Wrong answer0/334ms13312 KiB
21Accepted3/350ms13312 KiB
22Accepted3/350ms13180 KiB