Advertisement
jeff69

Untitled

Feb 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. #include <iomanip>
  11. #include <iostream>
  12. #include <functional>
  13. #include <algorithm>
  14. #include <math.h>
  15. #include <cmath>
  16. #include <string>
  17.  
  18. using namespace std;
  19.  
  20. int main(){
  21.  
  22.  
  23.  
  24. int n;
  25. int s = 0, z, x, v = 0, z1 = 0, z2 = 0, z3 = 0, z4 = 0;
  26. cin >> n;
  27. for (int i = 0; i < n; i++){
  28. cin >> x;
  29. if (x == 1)z1++;
  30. else if (x == 2)z2++;
  31. else if (x == 3)z3++;
  32. else z4++;
  33. }
  34.  
  35.  
  36. //8
  37. //2 3 4 4 2 1 3 1
  38. v = z4 + min(z3, z1) + z2 / 2;
  39. int bx = min(z1, z3);
  40. z3 = z3 - bx;
  41. if (z3 < 0)z3 = 0;
  42. z1 = z1 - bx;
  43. if (z1 < 0)z1 = 0;
  44. z2 = z2 % 2;
  45.  
  46.  
  47. int h = 2 * z2 + z1;
  48. if (h % 4 == 0)h = h / 4;
  49. else h = h / 4 + 1;
  50. v += h;
  51. v += z3;
  52. cout << v;
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement