Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int n,a[100004],t1,t2,t3,t4,res;
- int main()
- {
- cin>>n;
- for(int i=1;i<=n;++i)
- {
- cin>>a[i];
- if(a[i]==1) t1++;
- if(a[i]==2) t2++;
- if(a[i]==3) t3++;
- if(a[i]==4) t4++;
- }
- res=t4;
- if(t2%2==0) res+=t2/2;
- else
- {
- res+=t2/2+1;
- t1-=2;
- }
- if(t1>0)
- {
- res+=t3;
- t1-=t3;
- }
- else
- {
- cout<<res+t3;
- return 0;
- }
- if(t1>0)
- {
- if(t1%4==0) res+=t1/4;
- else res+=t1/4+1;
- }
- cout<<res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement