Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,a[100004],t1,t2,t3,t4,res;
  5.  
  6. int main()
  7. {
  8. cin>>n;
  9. for(int i=1;i<=n;++i)
  10. {
  11. cin>>a[i];
  12. if(a[i]==1) t1++;
  13. if(a[i]==2) t2++;
  14. if(a[i]==3) t3++;
  15. if(a[i]==4) t4++;
  16. }
  17.  
  18. res=t4;
  19. if(t2%2==0) res+=t2/2;
  20. else
  21. {
  22. res+=t2/2+1;
  23. t1-=2;
  24. }
  25. if(t1>0)
  26. {
  27. res+=t3;
  28. t1-=t3;
  29. }
  30. else
  31. {
  32. cout<<res+t3;
  33. return 0;
  34. }
  35. if(t1>0)
  36. {
  37. if(t1%4==0) res+=t1/4;
  38. else res+=t1/4+1;
  39. }
  40. cout<<res;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement