26562023-01-18 12:49:17kicsiboglarTalálkozáscpp11Hibás válasz 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;

}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base47/55
1Elfogadva0/03ms1824 KiB
2Elfogadva0/075ms13440 KiB
3Hibás válasz0/22ms2368 KiB
4Elfogadva2/22ms2456 KiB
5Elfogadva2/22ms2500 KiB
6Elfogadva2/22ms2884 KiB
7Elfogadva2/22ms3092 KiB
8Elfogadva3/32ms3088 KiB
9Elfogadva3/32ms3316 KiB
10Elfogadva3/32ms3528 KiB
11Elfogadva3/37ms5104 KiB
12Elfogadva3/38ms5748 KiB
13Elfogadva3/38ms5756 KiB
14Elfogadva3/314ms7428 KiB
15Elfogadva3/316ms7448 KiB
16Elfogadva3/314ms7400 KiB
17Elfogadva3/314ms7428 KiB
18Elfogadva3/325ms10000 KiB
19Hibás válasz0/381ms12488 KiB
20Hibás válasz0/320ms4192 KiB
21Elfogadva3/372ms15340 KiB
22Elfogadva3/371ms15380 KiB