/*

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. 配置IIS支持Json格式

    配置iis支持.json格式的文件 原文地址:http://blog.eroad.info/iis-suport-json/ 在做easyUI的官方示例的时候 有的例子是直接读取的json文件,但是默 ...

  2. 零基础用Docker部署微服务

    1. docker架构 这里的Client和DOCKER_HOST(docker server)都是在本地的,docker仓库Registry是在远程的: Client的docker命令通过Docke ...

  3. 安装 protoc 的各种坑

    首先下载 protoc 2.6.1   https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.g ...

  4. url中传递中文参数时的转码与解码

    URL传递中文参数时的几种处理方式,总结如下: 1.将字符串转码:newString(“xxxxx”.getBytes("iso-8859-1"),"utf-8" ...

  5. Centos7 安装mysql5.7.24

    从mysql官网下载 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz 拷贝到Centos的/opt目录下 1. 解压缩 tar -xzvf mysql-5.7.2 ...

  6. javascript学习笔记(七):事件详解

    HTML事件处理 <!DOCTYPE html> <html> <head lang="en"> <meta chaset="U ...

  7. Numpy:ndarray数据类型和运算

    Numpy的ndarray:一种多维数组对象 N维数组对象,该对象是一个快速而灵活的大数据集容器,nadarry是一个通用的同构数据多维容器,也就是说,其中的所有元素必须是相同类型的.每个数组都有一个 ...

  8. cloudstack4.11+KVM+4网卡bond5+briage 交换机不作配置

    网卡绑定配置 # cat ifcfg-em1TYPE=EthernetBOOTPROTO=noneDEVICE=em1ONBOOT=yesMASTER=bond0SLAVE=yes# cat ifcf ...

  9. 关于 No buffer space available (maximum connections reached?): connect 的处理

    一.问题: hudson一个应用打包部署一直不成功,检查报错 检查项目的JOB配置,开始以为是SVN的问题,但是重启SVN后问题一直存在 二.分析: TCP协议中,关闭TCP连接的是Server端(当 ...

  10. perl-基础

    1.关系运算符 数字: == != < <= > >= 字符串: eq ne lt le  gt   ge 2.循环 循环:while(){}   for(){}   last ...