-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12.py
More file actions
60 lines (40 loc) · 784 Bytes
/
12.py
File metadata and controls
60 lines (40 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# http://codeforces.com/problemset/problem/158/B
import math
n = int(input())
li = list(map(int, input().split()))
count = 0
one_count = 0
two_count = 0
three_count = 0
for i in li:
if i==4:
count+=1
elif i==3:
three_count+=1
elif i==2:
two_count+=1
elif i==1:
one_count+=1
# li.remove(i)
count += three_count
one_count -= three_count
if two_count>=2:
if two_count%2 == 0:
count += int(two_count/2)
two_count = 0
else:
count += int((two_count-1)/2)
two_count = 1
if one_count>0 and two_count>0:
one_count -= 2
count += 1
two_count = 0
if two_count > 0:
count += 1
if one_count>=4:
rem = int(one_count/4)
count += rem #+ (one_count%4)
one_count = one_count%4
if one_count>0:
count += 1
print(int(count))