-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
76 lines (73 loc) · 1.04 KB
/
B.cpp
File metadata and controls
76 lines (73 loc) · 1.04 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
69
70
71
72
73
74
75
76
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int c1=0,c2=0,c3=0,c4=0,t=0;
for(int i=0;i<n;i++)
{
if(a[i]==1)
c1++;
else if(a[i]==2)
c2++;
else if(a[i]==3)
c3++;
else if(a[i]==4)
c4++;
}
t+=c4;
if(c3>=c1)
{
t+=c3;
c1=0;
c3=0;
}
else
{
t+=c3;
c1=c1-c3;
c3=0;
}
if(c2%2==0)
{
t+=c2/2;
if(c1%4==0)
{
t+=c1/4;
}
else
{
t+=c1/4+1;
}
cout<<t;
}
else
{
t+=c2/2;
if(c1<=2)
{
t+=1;
}
else
{
t++;
c1=c1-2;
if(c1%4==0)
{
t+=c1/4;
}
else
{
t+=c1/4+1;
}
}
cout<<t;
}
return 0;
}