Editorial for Контролно


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: maya

Тестовете можете да видите тук.

Примерно решение на C++:

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int a[12];
    int n,l,r;
    cin>>n>>l>>r;
    int p;int br=l;
    for (int i=0; i<=n+1; i++)a[i]=1;
    for (int i=1; i<=l; i++)
    {
        cin>>p;
        a[p]=0;
    }
    for (int i=1; i<=r; i++)
    {
        cin>>p;
        a[p]=2;
    }
    if (n-r<2) cout<<0<<endl;
    else if (n==l)cout<<n<<endl;
    else
    {
        for (int i=1; i<=n; i++)
            if (a[i]==0)
            {
                if (a[i-1]==2)
                {
                    a[i-1]=1;
                    a[i]=1;br--;
                }
                else if (a[i+1]==2)
                {
                    a[i+1]=1;
                    a[i]=1;br--;
                }
            }


            cout<<br<<endl;
    }
    return 0;
}

Comments

There are no comments at the moment.