26552023-01-18 12:10:12kicsiboglarTalálkozáscpp11Wrong answer 46/55272ms10508 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;
    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].st=true;
        x[2*i].value=b;
        x[2*i].st=false;
        
    }

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

    start=1;
    a=1;
    curr=2;
    ll middle=(n+1)/2;
    while (a<middle&&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>middle)
        {
            if (!x[start].st) a--;
            start++;
        }
        while (a==middle) 
        {
            if (!x[start].st) break;
            start++;
        }
        if (a>=middle&&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
base46/55
1Accepted0/03ms1976 KiB
2Accepted0/056ms8164 KiB
3Wrong answer0/22ms2220 KiB
4Partially correct1/22ms2344 KiB
5Accepted2/22ms2532 KiB
6Accepted2/22ms2656 KiB
7Accepted2/22ms2820 KiB
8Accepted3/32ms3024 KiB
9Accepted3/32ms3092 KiB
10Accepted3/32ms3316 KiB
11Accepted3/34ms3456 KiB
12Accepted3/36ms3860 KiB
13Accepted3/36ms4024 KiB
14Accepted3/310ms4576 KiB
15Accepted3/39ms4512 KiB
16Accepted3/39ms4652 KiB
17Accepted3/39ms4652 KiB
18Accepted3/316ms5820 KiB
19Wrong answer0/343ms10036 KiB
20Time limit exceeded0/3272ms6588 KiB
21Accepted3/356ms10508 KiB
22Accepted3/356ms10452 KiB