26582023-01-18 13:19:10kicsiboglarTalálkozáscpp11Wrong answer 9/5590ms15036 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) 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
base9/55
1Accepted0/03ms1832 KiB
2Wrong answer0/072ms13480 KiB
3Accepted2/22ms2228 KiB
4Wrong answer0/22ms2424 KiB
5Wrong answer0/22ms2500 KiB
6Wrong answer0/22ms2656 KiB
7Wrong answer0/22ms3004 KiB
8Wrong answer0/32ms3052 KiB
9Wrong answer0/32ms3268 KiB
10Wrong answer0/32ms3356 KiB
11Wrong answer0/37ms4924 KiB
12Wrong answer0/38ms5568 KiB
13Wrong answer0/38ms5684 KiB
14Wrong answer0/316ms7004 KiB
15Partially correct1/316ms7032 KiB
16Wrong answer0/314ms6888 KiB
17Partially correct1/316ms6916 KiB
18Wrong answer0/326ms9480 KiB
19Wrong answer0/390ms11964 KiB
20Accepted3/320ms3676 KiB
21Partially correct1/375ms15020 KiB
22Partially correct1/374ms15036 KiB