Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- #include <functional>
- #include <algorithm>
- #include <math.h>
- #include <cmath>
- #include <string>
- using namespace std;
- int main(){
- int n;
- int s = 0, z, x, v = 0, z1 = 0, z2 = 0, z3 = 0, z4 = 0;
- cin >> n;
- for (int i = 0; i < n; i++){
- cin >> x;
- if (x == 1)z1++;
- else if (x == 2)z2++;
- else if (x == 3)z3++;
- else z4++;
- }
- //8
- //2 3 4 4 2 1 3 1
- v = z4 + min(z3, z1) + z2 / 2;
- int bx = min(z1, z3);
- z3 = z3 - bx;
- if (z3 < 0)z3 = 0;
- z1 = z1 - bx;
- if (z1 < 0)z1 = 0;
- z2 = z2 % 2;
- int h = 2 * z2 + z1;
- if (h % 4 == 0)h = h / 4;
- else h = h / 4 + 1;
- v += h;
- v += z3;
- cout << v;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement