/*

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. WinForm textbox 全选

    原地址:忘了 textBox1.KeyPress += anyTextBox_KeyPress; private void anyTextBox_KeyPress(object sender, Sys ...

  2. 单点登录(SSO)解决方案之 CAS服务端数据源设置及页面改造

    接上篇 单点登录(SSO)解决方案之 CAS 入门案例 服务端数据源设置: 开发中,我们登录的user信息都是存在数据库中的,下面说一下如何让用户名密码从我们的数据库表中做验证. 案例中我最终把cas ...

  3. Android studio 安装中遇到一些问题的解决办法,分享一下

    从eclipse转到android studio也是很无耐,刚开始总是会遇到很多难题,但是都不要轻言放弃. 以下是我遇到的问题,并通过搜索引擎找到的解决办法,善用工具,善用头脑,勿为伸手之人. And ...

  4. zabbix主动监测客户端设置

    主动/被动模式 主动模式和被动模式的区别一开始我也非常模糊,其实这是zabbix的两种工作方式,是相对于zabbix的agent端来说的,定义为: 主动模式:zabbix的agent端,也就是客户端, ...

  5. 第九章 词典 (e)桶/计数排序

  6. 第二章 向量(d3)有序向量:Fibonacci查找

  7. Openstack 集群,及常用服务的 高可用 haproxy配置

    一.介绍 配置文件位置(yum 安装):/etc/haproxy/haproxy.cfg 全局配置 #------------------------------------------------- ...

  8. Hdu1805-Expression(表达式树模版题+层序遍历树+栈的基本应用)

    2018-11-23-02:27:37 原题链接 题目描述: 题目一目了然. 本题思路: 本题很容易能想到是构建表达式树然后按照层序逆序输出即可. AC代码: #include <cstdio& ...

  9. PHP20-challenge12

      看下eval+var_dump的妙用.   eval会执行括号中的内容:var_dump中内容是字符串时输出的模式是 string(x) "xxxx".如果他俩结合,是可以很好 ...

  10. Codeforces Beta Round #44 (Div. 2)

    Codeforces Beta Round #44 (Div. 2) http://codeforces.com/contest/47 A #include<bits/stdc++.h> ...