26592023-01-18 13:21:01kicsiboglarTalálkozáscpp11Partially correct 51/5586ms15456 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=e.first;
        }
    }
    
    cout<<mini<<"\n"<<pos-mini+1<<" "<<pos;

}
SubtaskSumTestVerdictTimeMemory
base51/55
1Accepted0/03ms1700 KiB
2Accepted0/078ms13348 KiB
3Partially correct1/22ms2212 KiB
4Accepted2/22ms2268 KiB
5Accepted2/22ms2472 KiB
6Accepted2/22ms2704 KiB
7Accepted2/22ms3048 KiB
8Accepted3/32ms2976 KiB
9Accepted3/32ms3244 KiB
10Accepted3/32ms3492 KiB
11Accepted3/37ms5004 KiB
12Accepted3/39ms5776 KiB
13Accepted3/39ms5868 KiB
14Accepted3/317ms7256 KiB
15Accepted3/317ms7168 KiB
16Accepted3/316ms7320 KiB
17Accepted3/316ms7300 KiB
18Accepted3/328ms9876 KiB
19Wrong answer0/386ms12380 KiB
20Accepted3/320ms4196 KiB
21Accepted3/378ms15448 KiB
22Accepted3/376ms15456 KiB