fork download
  1. /*
  2.   Cred : SunnyYeahBoi
  3.   It's my last chance (⌐■_■)
  4.   Problem :
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. #define int long long
  12. #define double long double
  13. #define endl "\n"
  14. #define NAME "a"
  15.  
  16. const int MAXN = 1e6 + 5;
  17. const int inf = 1e18;
  18. const int MOD = 1e9 + 7;
  19.  
  20. void FileInput(){
  21. if(fopen(NAME".inp" , "r") == NULL)
  22. freopen(NAME".inp" , "w" , stdout);
  23. freopen(NAME".inp" , "r" , stdin);
  24. freopen(NAME".out" , "w" , stdout);
  25. }
  26.  
  27. int n;
  28. int cnt[5];
  29.  
  30. void solve(){
  31. cin >> n;
  32. for(int i = 1 ; i <= n ; i++){
  33. int x;
  34. cin >> x;
  35. cnt[x]++;
  36. }
  37.  
  38. int res = 0 , t;
  39. res += cnt[4];
  40. t = min(cnt[1] , cnt[3]);
  41. cnt[1] -= t;
  42. cnt[3] -= t;
  43. res += t;
  44. if(cnt[3] > 0) res += cnt[3];
  45. t = cnt[2] / 2;
  46. res += t;
  47. cnt[2] = cnt[2] % 2;
  48. res += (cnt[1] + cnt[2] * 2 + 3) / 4;
  49.  
  50. cout << res << endl;
  51. }
  52.  
  53. int32_t main(){
  54. FileInput();
  55. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  56. int t = 1;
  57. // cin >> t;
  58. while(t--)
  59. solve();
  60. return 0;
  61. }
  62.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty