/*

After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output

Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Example

Input
5
1 2 4 3 3
Output
4
Input
8
2 3 4 4 2 1 3 1
Output
5

Note

In the first test we can sort the children into four cars like this:

  • the third group (consisting of four children),
  • the fourth group (consisting of three children),
  • the fifth group (consisting of three children),
  • the first and the second group (consisting of one and two children, correspondingly).

There are other ways to sort the groups into four cars.

*/

#include <iostream>

using namespace std;

int main() {
    int n;
    int x;
    cin>>n;
    int counter = ;
    int num1 = , num2 = , num3 = ;
    while(n--)
    {
        cin >> x;
        if (x == )
        {
            num1++;
        }
        if (x == )
        {
            num2++;
        }
        if (x == )
        {
            num3++;
        }
        if (x == )
        {
            counter++;
        }
    }
    if (num3 >= num1)
    {
        counter += num3;
        counter += ( (num2 + ) / );//无论 num2 为偶数还是奇数都为(num2 + 1)/ 2
    }
    if (num3 < num1)
    {
        counter += num3;
        num1 = num1 - num3;
        counter += (num2 / );
        num2 = num2 % ;
        if (num2 == )
        {
            counter += (num1 + ) / + ;
        }
        if (num2 == )
        {
            if (num1 > )
            {
                counter += (num1 - ) / + ;
            }
            if (num1 == )
            {
                counter = counter + ;
            }
        }
    }
    cout << counter << endl;
    return ;
}

Taxi的更多相关文章

  1. 【HDU1960】Taxi Cab Scheme(最小路径覆盖)

    Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. A cost-effective recommender system for taxi drivers

    一个针对出租车司机有效花费的推荐系统 摘要 GPS技术和新形式的城市地理学改变了手机服务的形式.比如说,丰富的出租车GPS轨迹使得出做租车领域有新方法.事实上,最近很多工作是在使用出租车GPS轨迹数据 ...

  3. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  4. [ACM_数学] Taxi Fare [新旧出租车费差 水 分段函数]

    Description Last September, Hangzhou raised the taxi fares. The original flag-down fare in Hangzhou ...

  5. zjuoj 3600 Taxi Fare

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3600 Taxi Fare Time Limit: 2 Seconds    ...

  6. Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi

    Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi This spring, Kaggle hosted two competitions w ...

  7. poj 2060 Taxi Cab Scheme (最小路径覆盖)

    http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submi ...

  8. The 9th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Taxi Fare

    Problem A: Taxi Fare Time Limit: 2 Seconds Memory Limit: 65536 KB Last September, Hangzhou raised th ...

  9. Taxi Cab Scheme POJ && HDU

    Online Judge Problem Set Authors Online Contests User Web Board Home Page F.A.Qs Statistical Charts ...

  10. 二分图最小路径覆盖--poj2060 Taxi Cab Scheme

    Taxi Cab Scheme 时间限制: 1 Sec  内存限制: 64 MB 题目描述 Running a taxi station is not all that simple. Apart f ...

随机推荐

  1. Oracle ORA-00911: 无效字符

    SQL语句后多了个分号 “ ; ”.

  2. 学JS的心路历程-函式(五)箭头函式

    箭头函式arrow function 为了能够以更简短的方式建立函式,ES6变推出了箭头函式. 用说明的可能会不太懂,我们先拿之前的数组排序例子来看: var arr = [2,1,6,12,3,77 ...

  3. vue 异步请求

    摘自 ECMAScript 6 简介: 大家习惯将 ECMAScript 6.0 简称为 ES6,它是 Javascript 语言的下一代标准,它的目标,是使得 Javascript 语言可以用来编写 ...

  4. el-js中循环遍历el的集合

    遇到问题的代码: var score=0; for(var i=0;i<${fn:length(tMovie.tComments) };i++){ score=${tMovie.tComment ...

  5. SpringBoot @Aspect

    1.添加maven依赖注解 <!--springBoot的aop--> <dependency> <groupId>org.springframework.boot ...

  6. java中几个happens-before规则

    1. 程序顺序规则:一个线程中的每个操作,happens-before 该线程中的任意后续操作. 2.监视器锁规则:对一个锁的解锁, happens-before 于随后对这个锁的加锁操作 3.vol ...

  7. cacti报ERROR: unknown option '--border' 解决方法

    cacti制图报下面提示 if (isset($rrdborder) && $rrdversion >= 1.4) { $graph_opts .= "--border ...

  8. Appium1.6 定位iOS元素和操作元素

    元素定位方式  第一种:通过Appium1.6的Inspector来查看 具体安装方式前面的随笔已经介绍了:http://www.cnblogs.com/meitian/p/7360017.html ...

  9. Redis数据结构的多种用法

    分布式锁(string) setnx key value,当key不存在时,将 key 的值设为 value ,返回1.若给定的 key 已经存在,则setnx不做任何动作,返回0. 当setnx返回 ...

  10. leetcode 中等题(1)

    2. Add Two Numbers(中等) /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis ...