13582022-05-22 18:06:19nkdorka1212Találkozáscpp11Wrong answer 50/5561ms10496 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/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
base50/55
1Accepted0/04ms3120 KiB
2Accepted0/061ms4392 KiB
3Wrong answer0/23ms4400 KiB
4Accepted2/23ms4400 KiB
5Accepted2/23ms4408 KiB
6Accepted2/23ms4412 KiB
7Accepted2/23ms4416 KiB
8Accepted3/33ms4420 KiB
9Accepted3/33ms4424 KiB
10Accepted3/33ms4428 KiB
11Accepted3/36ms4432 KiB
12Accepted3/38ms4628 KiB
13Accepted3/38ms4732 KiB
14Accepted3/313ms4836 KiB
15Accepted3/313ms5044 KiB
16Accepted3/313ms5252 KiB
17Accepted3/313ms5556 KiB
18Accepted3/318ms5784 KiB
19Wrong answer0/361ms7168 KiB
20Accepted3/352ms8168 KiB
21Accepted3/361ms9324 KiB
22Accepted3/359ms10496 KiB