-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCars.php
More file actions
46 lines (39 loc) · 784 Bytes
/
Cars.php
File metadata and controls
46 lines (39 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
<?php
/**
* @author Sunwaurl
* PHP 7.2
*/
error_reporting(0);
$temp = $total = 0;
$count1 = $count2 = $count3 = 0;
$n = (int) fgets(STDIN);
$g = [];
$g = array_map('intval', explode(' ', fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
if ($n == 1) {
$total++;
break;
}
if ($g[$i] == 1) $count1++;
else if ($g[$i] == 2) $count2++;
else if ($g[$i] == 3) {
$count3++;
$total++;
} else {
$total++;
}
}
$count2 = $count2 * 2;
$total += $count2 / 4;
$left = $count2 % 4;
if ($count3 >= $count1) {
$count1 = 0;
} else {
$count1 = $count1 - $count3;
}
$temp = $left + $count1;
while ($temp > 0) {
$total++;
$temp = $temp - 4;
}
echo (int) $total . "\n";