Codeforces Taxi

/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.

*/

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back

typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;

const int mod = 1000007;
const int high = 100003;

int ar[high];

int main()
{
    fast;
    int n , x , i , j , cnt=0;
    while(cin >> n)
    {
        for(i=0; i<n; i++)
        {
            cin >> ar[i];
        }

        sort(ar , ar+n);

        i=0;
        j=n-1;
        cnt=0;

        for(i=0, j=n-1; i<=j;)
        {
            if(i == j)
            {
                cnt++;
                break;
            }

            int def = 4 - ar[j];

            if(ar[i] <= def)
            {
                i++;
                ar[j]+=ar[i];
            }

            else
            {
                cnt++;
                j--;
            }
        }

        outn(cnt);
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number