25652023-01-17 11:39:55kicsiboglarTalálkozáscpp11Wrong answer 4/5550ms13840 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,nr;
    bool st;
};

bool compare (const adat& a, const adat &b)
    {
        return a.value<b.value;
    }

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

    cin>>n;
    vector <adat> x(2*n+1);
    for (i=1;i<=n;++i)
    {
        cin>>a>>b;
        x[2*i-1].value=a;
        x[2*i-1].nr=i;
        x[2*i-1].st=true;
        x[2*i].value=b;
        x[2*i].nr=i;
        x[2*i].st=false;
        
    }

    sort (x.begin()+1, x.end(),compare);

    //for (auto &e:x) cout<<e.value<<" "<<e.st<<"\n";

    //vector <bool> opened(n+1,false);
    //map<ll,bool> opened;
    a=0;

    start=1;
    a=1;
    curr=2;
    while (a<n/2&&curr<=2*n)
    {
        if (x[curr].st) a++;
        curr++;
    }
    while (curr<=2*n)
    {
        if (x[curr].st) a++;
        while (start<=curr&&a>n/2)
        {
            if (!x[start].st) a--;
            start++;
        }
        if (x[curr].value-x[start].value+1<mini)
        {
            mini=x[curr].value-x[start].value+1;
            pos=x[start].value;
        }
        curr++;
    }

    /*for (i=1;i<2*n;++i)
    {
        start=x[i].value;
        if (x[i].st) a++;//opened[x[i].nr]=true;
        nr=a;
        //for (j=1;j<=n;++j) opened[j]=false;
        //opened.clear();
        for (j=i+1;j<=2*n;++j)
        {
            if (x[j].st) 
            {
                nr++;
                //opened[x[j].nr]=true;
            }
            //else if (!opened[x[j].nr]) nr++;
            if (nr>=n/2)
            {
                if (x[j].value-start+1<mini)
                {
                    mini=x[j].value-start+1;
                    pos=start;
                }
                break;
            }
            
        }
        if (!x[i].st) a--;
    }*/

    cout<<mini<<"\n"<<pos<<" "<<pos+mini-1;

}
SubtaskSumTestVerdictTimeMemory
base4/55
1Accepted0/03ms1832 KiB
2Wrong answer0/050ms11284 KiB
3Wrong answer0/22ms2284 KiB
4Wrong answer0/22ms2476 KiB
5Wrong answer0/22ms2680 KiB
6Wrong answer0/22ms2892 KiB
7Wrong answer0/22ms2980 KiB
8Wrong answer0/32ms3092 KiB
9Wrong answer0/32ms3280 KiB
10Wrong answer0/32ms3484 KiB
11Wrong answer0/34ms3844 KiB
12Wrong answer0/36ms4552 KiB
13Wrong answer0/36ms4796 KiB
14Wrong answer0/39ms5480 KiB
15Partially correct1/39ms5784 KiB
16Wrong answer0/38ms5392 KiB
17Partially correct1/39ms5688 KiB
18Wrong answer0/316ms6984 KiB
19Wrong answer0/339ms13492 KiB
20Wrong answer0/335ms13768 KiB
21Partially correct1/350ms13840 KiB
22Partially correct1/350ms13668 KiB