日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > 158B - Taxi

158B - Taxi

來源:程序員人生   發布時間:2014-12-24 08:47:22 閱讀次數:3106次
B. Taxi
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
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.

import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int n1=0,n2=0,n3=0,count=0; for(int i=0;i<n;i++) { int x=sc.nextInt(); if(x==1) n1++; if(x==2) n2++; if(x==3) n3++; if(x==4) count++; } if(n3>=n1) {count+=n3;count+=(n2+1)/2;} else { count+=n3+n2/2;n1-=n3; if(n2%2==0&&n1>0) count+=(n1⑴)/4+1; else count+=(n1+1)/4+1; } System.out.println(count); } }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 一区网站在线观看 | 国产专区精品 | 日韩精品99| 在线免费成人 | 精品国产31久久久久久 | 亚洲精品乱码久久久久v最新版 | 国产日韩欧美一区二区 | 久久久久久久91 | 可以免费看av的网站 | 国产高清在线 | 国产三级精品片 | 天堂视频在线观看 | 精品久久久久久久久久久下田 | a v视频在线播放 | 玖玖在线播放 | 免费在线成人av | 久久久国产视频 | 亚洲综合区| 精品香蕉视频 | 亚洲成年 | 日韩三级免费观看 | 最新日韩在线 | 毛片久久久 | 麻豆成人入口 | 91精品国产综合久久国产大片 | 国产尤物一区 | 亚洲视频一二三区 | 天堂一区| 亚洲激情视频在线播放 | 欧美在线视频一区二区 | 久久午夜电影 | 午夜特黄 | 激情毛片| 欧美在线一区二区三区 | 亚洲一区二区三区在线视频观看 | 欧美天天 | 一区二区三区在线观看视频 | 国产天堂av | 欧美成人高清视频 | 久久久毛片 | 国产精品不卡在线 |