fork download
  1. /*
  2.  ███╗ ███╗ █████╗ ██████╗ ██╗ █████╗ ███╗ ███╗ ███╗ ██╗ █████╗ ██████╗ ███████╗██╗ ██╗
  3.  ████╗ ████║██╔══██╗██╔══██╗██║██╔══██╗████╗ ████║ ████╗ ██║██╔══██╗██╔══██╗██╔════╝██║ ██║
  4.  ██╔████╔██║███████║██████╔╝██║███████║██╔████╔██║ ██╔██╗ ██║███████║██████╔╝█████╗ ███████║
  5.  ██║╚██╔╝██║██╔══██║██╔══██╗██║██╔══██║██║╚██╔╝██║ ██║╚██╗██║██╔══██║██╔══██╗██╔══╝ ██╔══██║
  6.  ██║ ╚═╝ ██║██║ ██║██║ ██║██║██║ ██║██║ ╚═╝ ██║ ██║ ╚████║██║ ██║██████╔╝███████╗██║ ██║
  7.  ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═══╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝ ╚═╝
  8. */
  9.  
  10. #include <iostream>
  11. #include <algorithm>
  12. #include <string>
  13. #include <vector>
  14. #include <queue>
  15. #include <deque>
  16. #include <stack>
  17. #include <set>
  18. #include <numeric>
  19.  
  20. using namespace std;
  21. using ll = long long;
  22.  
  23. #define el '\n'
  24. const ll MOD = 1e9 + 7;
  25.  
  26. int main(){
  27. using namespace std;
  28.  
  29.  
  30. int n,x,four=0,three=0,two=0,one=0;
  31. cin>>n;
  32. for(int i=0 ; i<n ; i++)
  33. {
  34. cin>>x;
  35. if(x==4)
  36. four++;
  37. else if(x==3)
  38. three++;
  39. else if(x==2)
  40. two++;
  41. else
  42. one++;
  43. }
  44. int groups=four;
  45. groups+=three;
  46. if(three>=one)
  47. {
  48. one=0;
  49. }
  50. else{
  51. one-=three;
  52. }
  53.  
  54. groups+=two/2;
  55. two=two%2;
  56.  
  57. if(one<=2)
  58. {
  59. if(one>0 || two>0)
  60. groups++;
  61. }
  62. else{
  63. if(two==1)
  64. {
  65. groups++;
  66. one-=2;
  67. }
  68.  
  69. groups+=one/4;
  70.  
  71. if(one%4!=0)
  72. {
  73. groups++;
  74. }
  75. }
  76. cout<<groups;
  77.  
  78. return 0;}
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty