489B codeforces - BerSU Ball

489B codeforces


BerSu Ball

Solution in c++

#include <iostream>

#include <cmath>

using namespace std;

int g[2000]={0},b[2000]={0};

int main()

{

    int bo,gi,sol=0,t;

    cin>>bo;

    for(int i=0;i<bo;i++)

    {

        cin>>t;

        b[t]++;

    }

    cin>>gi;

    for(int i=0;i<gi;i++){

        cin>>t;

        g[t]++;

    }

    for(int i=1;i<=100;i++){

        sol+=min(b[i],g[i]);

        int mn=min(b[i],g[i]);

        b[i]-=mn;

        g[i]-=mn;

        sol+=min(b[i],g[i+1]);

         mn=min(b[i],g[i+1]);

        b[i]-=mn;

        g[i+1]-=mn;

        sol+=min(g[i],b[i+1]);

        mn=min(g[i],b[i+1]);

        g[i]-=mn;

        b[i+1]-=mn;

    }

    cout<<sol<<"\n";

    return 0;

}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق