CF158B.Taxi

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 s__i friends (1 ≤ s__i ≤ 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)?

下课后,有 nn 组小学生走出教室,决定前往波利卡普斯家为其庆祝生日。已知第 ii 组由 sis_i 名朋友组成(1 ≤ si ≤ 41 \le s_i \le 4),且该组所有成员必须一同前往。他们决定乘坐出租车抵达。每辆出租车最多可载 4 名乘客。若要求每组的所有成员必须乘坐同一辆出租车(但一辆出租车可搭载多个小组),那么孩子们最少需要多少辆出租车?

输入格式

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

第一行包含一个整数 nn(1 ≤ n ≤ 1051 \leq n \leq 10^5)—— 学生小组的数量。
第二行包含一个整数序列 s1, s2, ..., sns_1,\,s_2,\,...,\,s_n(1 ≤ si ≤ 41 \leq s_i \leq 4)。这些整数以空格分隔,其中 sis_i 表示第 ii 个小组的学生人数。

输出格式

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

输出一个数字——即运送所有儿童前往波利卡普斯所需的出租车最少数量。

输入输出样例

  • 输入#1

    5
    1 2 4 3 3

    输出#1

    4
  • 输入#2

    8
    2 3 4 4 2 1 3 1

    输出#2

    5

说明/提示

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.

在第一个测试用例中,我们可以将孩子们按如下方式分配到四辆车上:

  • 第三组(包含四名儿童),
  • 第四组(包含三名儿童),
  • 第五组(包含三名儿童),
  • 第一组和第二组(分别包含一名和两名儿童)。

将各组分配到四辆车上的方法还有其他多种。

输入解题思路,AI测评打分。不知道怎么写?

首页