26562023-01-18 12:49:17kicsiboglarTalálkozáscpp11Wrong answer 47/5581ms15380 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;
};

struct element
{
    ll start=0,stop=0;
};

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);
    map<ll,element> x;
    for (i=1;i<=n;++i)
    {
        cin>>a>>b;
        x[a].start++;
        x[b].stop++;
        /*x[2*i-1].value=a;
        x[2*i-1].st=true;
        x[2*i].value=b;
        x[2*i].st=false;*/
        
    }
    deque <ll> v;
    //v.push_back(x.begin()->first);
    a=0;
    ll half=(n+1)/2;
    for (auto &e:x)
    {
        v.push_back(e.first);
        a+=e.second.start;
        while (!v.empty()&&a>half)
        {
            a-=x[v[0]].stop;
            v.pop_front();
        }
        while (a==half&&!v.empty())
        {
            if (x[v[0]].stop) break;
            else v.pop_front();
        }
        if (a>=half&&e.first-v[0]+1<mini)
        {
            mini=e.first-v[0]+1;
            pos=e.first;
        }
        //a-=e.second.stop;
    }
    //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-mini+1<<" "<<pos;

}
SubtaskSumTestVerdictTimeMemory
base47/55
1Accepted0/03ms1824 KiB
2Accepted0/075ms13440 KiB
3Wrong answer0/22ms2368 KiB
4Accepted2/22ms2456 KiB
5Accepted2/22ms2500 KiB
6Accepted2/22ms2884 KiB
7Accepted2/22ms3092 KiB
8Accepted3/32ms3088 KiB
9Accepted3/32ms3316 KiB
10Accepted3/32ms3528 KiB
11Accepted3/37ms5104 KiB
12Accepted3/38ms5748 KiB
13Accepted3/38ms5756 KiB
14Accepted3/314ms7428 KiB
15Accepted3/316ms7448 KiB
16Accepted3/314ms7400 KiB
17Accepted3/314ms7428 KiB
18Accepted3/325ms10000 KiB
19Wrong answer0/381ms12488 KiB
20Wrong answer0/320ms4192 KiB
21Accepted3/372ms15340 KiB
22Accepted3/371ms15380 KiB