-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtaxi.py
More file actions
48 lines (44 loc) · 860 Bytes
/
Copy pathtaxi.py
File metadata and controls
48 lines (44 loc) · 860 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
#http://codeforces.com/problemset/problem/158/B
from collections import Counter
def taxi():
int(raw_input())
groups = raw_input().strip().split()
counter = Counter(groups)
total = 0
flag_3 = False
flag_2 = False
if '4' in counter:
total += counter['4']
if '3' in counter:
total += counter['3']
flag_3 = True
if '2' in counter:
count = counter['2'] // 2
total += count
if counter['2'] % 2 != 0:
if '1' in counter:
flag_2 = True
else:
total += 1
if '1' in counter:
count_1 = counter['1']
if flag_3:
count_3 = counter['3']
if count_1 > count_3:
count_1 -= count_3
else:
count_1 = 0
count = count_1 // 4
total += count
rem = count_1 % 4
if flag_2:
total += 1
if rem > 2:
rem -= 2
else:
rem = 0
if rem != 0:
total += 1
return total
if __name__ == '__main__':
print taxi()