Codeforces 158B - Taxi Solution

 ///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

///Abul Hasnat  Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    #include<bits/stdc++.h>

    using namespace std;

    int main()

    {

        int t,n,i,c1=0,c2=0,c3=0,c4=0,c=0;

        cin>>n;

        int a[n+9];

        for(i=0; i<n; i++)

        {

            cin>>a[i];

            if(a[i]==1)c1++;

            else if(a[i]==2)c2++;

            else if(a[i]==3)c3++;

            else if(a[i]==4)c4++;

        }

        c+=c4;

        while(c1!=0&&c3!=0)

        {

            c++,c1--,c3--;

        }

        if(c1==0&&c3!=0)

        {

            c+=c3;

            c3=0;

        }

        c+=c2/2;

        if(c2%2!=0)

        {

            if(c1<=2)

            {

                c++;

                c2=0;

                c1=0;

            }

            else

            {

                c++;

                c1-=2;

                c2=0;

            }

        }

        if(c1!=0)

        {

            c+=c1/4;

            if(c1%4!=0)

            c++;

        }

        cout<<c<<endl;

    }



    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

    Powered by Blogger.