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 925 (Div. 3) 1931D. Divisible Pairs Solution

        Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

    Powered by Blogger.