Advertisement
rengetsu

Codeforces_158B

Jul 30th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. //Codeforces Round 158B
  2. #include <cmath>
  3. #include <iostream>
  4. using namespace std;
  5. int del(int a, int b) {
  6.     return a/b + (a%b>0);
  7. }
  8. int main () {
  9.     int n, k, ans, mas[5] = {};
  10.     cin >> n;
  11.     for (int i=0; i<n; i++) {
  12.         cin >> k;
  13.         mas[k] ++;
  14.     }
  15.     ans = mas[4];
  16.     if (mas[3] <= mas[1]) {
  17.         ans += mas[3];
  18.         mas[1] -= mas[3];
  19.     }
  20.     else {
  21.         ans += mas[3];
  22.         mas[1] = 0;
  23.     }
  24.     mas[2] += del(mas[1], 2);
  25.     ans += del(mas[2], 2);
  26.     cout << ans;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement