fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n , one = 0 , two = 0 , three = 0 , four = 0 , ans = 0 ;
  6. cin>>n ;
  7. for(int i=1 ; i<=n ; i++)
  8. {
  9. int x ;
  10. cin>>x ;
  11. if(x==1)
  12. one++;
  13. else if(x ==2)
  14. two++;
  15. else if(x ==3)
  16. three++;
  17. else if(x ==4)
  18. four++;
  19. }
  20. ans += four ;
  21. ans += (two / 2) ;
  22. int mn = min(one , three) ;
  23. ans += mn ;
  24. one -= mn ;
  25. three -= mn ;
  26. ans += three ;
  27. int rem = two % 2 ;
  28. if(rem == 1)
  29. ans+= (one + 2 + 3) / 4 ;
  30. else
  31. ans+= (one + 3) /4 ;
  32. cout<<ans;
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5444KB
stdin
Standard input is empty
stdout
Standard output is empty