26532023-01-18 11:45:40kicsiboglarTalálkozáscpp11Wrong answer 43/55270ms13496 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)
    {
        if (a.st) return true;
        return false;
    }
    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 (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/03ms1704 KiB
2Accepted0/059ms11192 KiB
3Wrong answer0/22ms2124 KiB
4Wrong answer0/22ms2332 KiB
5Wrong answer0/22ms2320 KiB
6Accepted2/22ms2352 KiB
7Accepted2/22ms2448 KiB
8Accepted3/32ms2568 KiB
9Accepted3/32ms2776 KiB
10Accepted3/32ms2908 KiB
11Accepted3/34ms3528 KiB
12Accepted3/36ms4224 KiB
13Accepted3/36ms4120 KiB
14Accepted3/310ms4776 KiB
15Accepted3/310ms5164 KiB
16Accepted3/310ms4680 KiB
17Accepted3/310ms4940 KiB
18Accepted3/317ms6444 KiB
19Wrong answer0/346ms12892 KiB
20Time limit exceeded0/3270ms7700 KiB
21Accepted3/359ms13276 KiB
22Accepted3/359ms13496 KiB