26612023-01-18 13:27:18kicsiboglarTalálkozáscpp11Wrong answer 52/5586ms15248 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 element
{
    ll start=0,stop=0;
};


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

    cin>>n;
    map<ll,element> x;
    for (i=1;i<=n;++i)
    {
        cin>>a>>b;
        x[a].start++;
        x[b].stop++;
    }

    deque <ll> v;
    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)
        {
            if (a-x[v[0]].stop>=half)
            {
                a-=x[v[0]].stop;
                v.pop_front();
            }
            else break;
        }
        if (a>=half&&e.first-v[0]+1<mini)
        {
            mini=e.first-v[0]+1;
            pos=v[0];
        }
        while (a==half&&!v.empty())
        {
            if (x[v[0]].stop>0) break;
            else v.pop_front();
        }
        if (a>=half&&e.first-v[0]+1<mini)
        {
            mini=e.first-v[0]+1;
            pos=v[0];
        }
    }
    
    cout<<mini<<"\n"<<pos<<" "<<pos+mini-1;

}
SubtaskSumTestVerdictTimeMemory
base52/55
1Accepted0/03ms1700 KiB
2Accepted0/076ms13288 KiB
3Accepted2/22ms2068 KiB
4Accepted2/22ms2292 KiB
5Accepted2/22ms2524 KiB
6Accepted2/22ms2580 KiB
7Accepted2/22ms2848 KiB
8Accepted3/32ms2772 KiB
9Accepted3/32ms2792 KiB
10Accepted3/32ms2800 KiB
11Accepted3/37ms4088 KiB
12Accepted3/39ms4912 KiB
13Accepted3/39ms5152 KiB
14Accepted3/316ms6560 KiB
15Accepted3/316ms6840 KiB
16Accepted3/316ms6656 KiB
17Accepted3/316ms6948 KiB
18Accepted3/327ms9464 KiB
19Wrong answer0/386ms11952 KiB
20Accepted3/320ms3620 KiB
21Accepted3/375ms15248 KiB
22Accepted3/375ms15200 KiB