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

    RESTful APIs with CRUD Operations in Laravel 12| (2025)

      RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

    Powered by Blogger.