-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path158B.cpp
54 lines (53 loc) · 1.08 KB
/
158B.cpp
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
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <utility>
using namespace std;
int main()
{
int n, count = 0;
unordered_map<int, int> m;
cin >> n;
vector<int> v(n);
for(int i = 0 ; i < n ; i++)
{
cin >> v[i];
}
for(int i = 0 ; i < n ; i++)
{
if(m.find(v[i]) != m.end())
m[v[i]] += 1;
else
m[v[i]] = 1;
}
if(m.find(1) == m.end())
m[1] = 0;
if(m.find(4) != m.end() )
count = m[4];
for(int i = 3 ; i >= 2 ; i--)
{
if(i == 3 && m.find(3) != m.end())
{
count += m[3];
m[1] = m[3] >= m[1] ? 0 : m[1] - m[3];
}
if(i == 2 && m.find(2) != m.end())
{
count += m[2] / 2;
m[2] = m[2] & 1 ? 1 : 0;
if(m[2] > 0)
{
count += 1;
m[1] -= 2;
}
}
}
if(m[1] > 0)
count += (m[1] + 3)/4;
cout << count << endl;
return 0;
}