25632023-01-17 10:47:06kicsiboglarTalálkozáscpp11Time limit exceeded 8/55300ms10988 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;

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;
    for (i=1;i<2*n;++i)
    {
        start=x[i].value;
        //if (x[i].st) nr++;//opened[x[i].nr]=true;
        nr=1;
        //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;
            }
            
        }
    }

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

}
SubtaskSumTestVerdictTimeMemory
base8/55
1Accepted0/03ms1696 KiB
2Time limit exceeded0/0300ms9120 KiB
3Accepted2/22ms2184 KiB
4Wrong answer0/22ms2392 KiB
5Wrong answer0/22ms2588 KiB
6Wrong answer0/26ms2684 KiB
7Wrong answer0/210ms2692 KiB
8Accepted3/33ms2804 KiB
9Accepted3/34ms2996 KiB
10Wrong answer0/310ms2964 KiB
11Time limit exceeded0/3300ms2588 KiB
12Time limit exceeded0/3268ms2848 KiB
13Time limit exceeded0/3254ms3120 KiB
14Time limit exceeded0/3252ms4088 KiB
15Time limit exceeded0/3261ms4256 KiB
16Time limit exceeded0/3256ms4268 KiB
17Time limit exceeded0/3241ms4160 KiB
18Time limit exceeded0/3264ms5004 KiB
19Time limit exceeded0/3259ms10484 KiB
20Time limit exceeded0/3246ms10484 KiB
21Time limit exceeded0/3266ms10632 KiB
22Time limit exceeded0/3259ms10988 KiB