13572022-05-22 18:05:14nkdorka1212Találkozáscpp11Runtime error 4/554ms3820 KiB
#include <bits/stdc++.h>

using namespace std;
int ido=40;

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
base4/55
1Accepted0/02ms1740 KiB
2Runtime error0/04ms2164 KiB
3Wrong answer0/21ms1996 KiB
4Accepted2/21ms2004 KiB
5Accepted2/21ms2012 KiB
6Wrong answer0/21ms2036 KiB
7Wrong answer0/21ms2032 KiB
8Runtime error0/31ms2068 KiB
9Wrong answer0/31ms2052 KiB
10Wrong answer0/31ms2064 KiB
11Runtime error0/32ms2204 KiB
12Runtime error0/33ms2304 KiB
13Runtime error0/33ms2404 KiB
14Runtime error0/34ms2616 KiB
15Runtime error0/34ms2820 KiB
16Runtime error0/34ms3028 KiB
17Runtime error0/34ms3224 KiB
18Runtime error0/33ms3336 KiB
19Runtime error0/31ms3248 KiB
20Runtime error0/31ms3264 KiB
21Runtime error0/34ms3608 KiB
22Runtime error0/34ms3820 KiB