-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaxi.cpp
More file actions
69 lines (54 loc) · 1.22 KB
/
Copy pathTaxi.cpp
File metadata and controls
69 lines (54 loc) · 1.22 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<bits/stdc++.h>
using namespace std;
#define fer(i,a,b) for(re i = a; i<b; ++i)
#define re register int
#define pb push_back
#define ll long long
#define mod 1000000007
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pi;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n,t;
cin>>n;
int a[100005];
int taxi_cnt=0,ones=0,twos=0,threes=0,fours=0;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]==1) ones++;
if(a[i]==2) twos++;
if(a[i]==3) threes++;
if(a[i]==4) fours++;
}
taxi_cnt+=fours;
while(threes and ones){
threes-=1;
ones-=1;
taxi_cnt+=1;
}
if(threes and ones==0) taxi_cnt+=threes, threes-=1;
taxi_cnt=taxi_cnt+twos/2;
if(twos%2!=0){
if(ones<=2){
taxi_cnt+=1;
ones=0; twos=0;
}
else{
ones-=2;
twos=0;
taxi_cnt+=1;
}
}
if(ones!=0){
taxi_cnt+=ones/4;
if(ones%4!=0) taxi_cnt+=1;
}
cout<<taxi_cnt<<endl;
}