26602023-01-18 13:26:14kicsiboglarTalálkozáscpp11Partially correct 51/5586ms15680 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;
        }
        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
base51/55
1Accepted0/03ms1824 KiB
2Accepted0/075ms13444 KiB
3Partially correct1/22ms2228 KiB
4Accepted2/22ms2428 KiB
5Accepted2/22ms2628 KiB
6Accepted2/22ms2992 KiB
7Accepted2/22ms3092 KiB
8Accepted3/32ms3140 KiB
9Accepted3/32ms3488 KiB
10Accepted3/32ms3576 KiB
11Accepted3/37ms5120 KiB
12Accepted3/39ms5888 KiB
13Accepted3/39ms6132 KiB
14Accepted3/317ms7512 KiB
15Accepted3/316ms7532 KiB
16Accepted3/316ms7472 KiB
17Accepted3/316ms7636 KiB
18Accepted3/327ms10076 KiB
19Wrong answer0/386ms12560 KiB
20Accepted3/320ms4216 KiB
21Accepted3/375ms15412 KiB
22Accepted3/378ms15680 KiB