-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path158B.cpp
More file actions
41 lines (32 loc) · 706 Bytes
/
Copy path158B.cpp
File metadata and controls
41 lines (32 loc) · 706 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
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int main() {
int n;
cin >> n;
int arr[5] = {0, 0, 0, 0, 0};
while (n--) {
int g;
cin >> g;
arr[g]++;
}
int ans = arr[4];
arr[4] = 0;
// 3 1
int tmp = min(arr[3], arr[1]);
ans += tmp;
arr[3] -= tmp;
arr[1] -= tmp;
// 2 2
tmp = arr[2] / 2;
ans += tmp;
arr[2] -= 2 * tmp;
// 2 1 1
tmp = min((int)ceil((double)(arr[1] / 2.0)), arr[2]);
ans += tmp;
arr[2] -= tmp;
arr[1] -= 2 * tmp;
ans += arr[3] + arr[2] + ceil((double)arr[1] / 4.0);
printf("%d\n", ans);
}