48 lines
817 B
C++
48 lines
817 B
C++
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
int main(){
|
|
ios::sync_with_stdio(0);
|
|
cin.tie(0);
|
|
|
|
int n, a, result = 0, ones = 0, twos = 0, threes = 0;
|
|
cin >> n;
|
|
|
|
for(int i = 0; i < n; i++){
|
|
cin >> a;
|
|
if(a != 4){
|
|
if(a == 1){
|
|
ones++;
|
|
} else if(a == 2){
|
|
twos++;
|
|
} else{
|
|
threes++;
|
|
}
|
|
} else{
|
|
result++;
|
|
}
|
|
}
|
|
|
|
int onethreegroups = min(ones, threes);
|
|
result += threes;
|
|
ones -= onethreegroups;
|
|
|
|
int doubletwos = twos / 2;
|
|
result += doubletwos;
|
|
twos -= doubletwos * 2;
|
|
|
|
if(twos == 1){
|
|
result++;
|
|
ones -= min(2, ones);
|
|
}
|
|
|
|
result += ceil((float)ones / 4);
|
|
|
|
cout << result;
|
|
|
|
cout << flush;
|
|
|
|
return 0;
|
|
}
|