13592022-05-22 18:21:10nkdorka1212Találkozáscpp11Wrong answer 46/5561ms10492 KiB
#include <bits/stdc++.h>

using namespace std;
int ido=100002;

int main()
{
    int n;
    cin>>n;
    vector<int>elment(ido,0);
    vector<int>nemjott(ido,0);
    for(int i=1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        elment[b]++;
        nemjott[a]++;
    }
    for(int i=1;i<=ido;i++)
    {
        elment[i]=elment[i-1]+elment[i];
    }
    for(int i=ido-1;i>=1;i--)
    {
        nemjott[i]=nemjott[i+1]+nemjott[i];
    }
    int l=1,r=1;
    int mini=INT_MAX;
    int kezd=0;
    while(l<=ido)
    {
        while(elment[l-1]+nemjott[r+1]>(n+1)/2 && r<ido-1)
        {
            r++;
        }
        if(elment[l-1]+nemjott[r+1]<=(n+1)/2 && r-l+1<mini)
        {
            mini=r-l+1;
            kezd=l;
        }
        l++;
        //cout<<l<<" "<<r<<endl;
    }
    cout<<mini<<"\n";
    cout<<kezd<<" "<<kezd+mini-1<<"\n";
    return 0;
}
/*
    for(int i=1;i<=20;i++)
    {
        cout<<elment[i]<<" ";
    }
*/
SubtaskSumTestVerdictTimeMemory
base46/55
1Accepted0/03ms3116 KiB
2Accepted0/057ms4320 KiB
3Wrong answer0/22ms4396 KiB
4Wrong answer0/23ms4392 KiB
5Wrong answer0/23ms4396 KiB
6Accepted2/22ms4404 KiB
7Accepted2/23ms4408 KiB
8Accepted3/32ms4408 KiB
9Accepted3/33ms4412 KiB
10Accepted3/33ms4416 KiB
11Accepted3/36ms4420 KiB
12Accepted3/38ms4620 KiB
13Accepted3/38ms4724 KiB
14Accepted3/313ms4832 KiB
15Accepted3/313ms5036 KiB
16Accepted3/323ms5244 KiB
17Accepted3/313ms5448 KiB
18Accepted3/319ms5776 KiB
19Wrong answer0/361ms7036 KiB
20Accepted3/357ms8160 KiB
21Accepted3/359ms9316 KiB
22Accepted3/359ms10492 KiB