반응형

 

#include<stdio.h>
#include<algorithm>
#include<math.h>

int main()
{
	int n;
	int arr[100001];
	int ans = 0;
	double cnt1, cnt2, cnt3, cnt4;
	cnt1 = cnt2 = cnt3 = cnt4 = 0;
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);

		if (arr[i] == 1) cnt1++;
		if (arr[i] == 2) cnt2++;
		if (arr[i] == 3) cnt3++;
		if (arr[i] == 4) cnt4++;
	}

	if (cnt3 >= cnt1)
	{
		ans = cnt4 + cnt3 + ceil(cnt2 / 2);
	}
	else // cnt3 < cnt1
	{
		ans = cnt4 + cnt3;
		cnt1 = cnt1 - cnt3;
		ans = ans + ceil((2 * cnt2 + cnt1) / 4);
	}
	
	printf("%d", ans);

}

 

https://codeforces.com/contest/158/problem/B

 

Problem - B - Codeforces

 

codeforces.com

 

반응형

'🧩PS > 🥈Nomal' 카테고리의 다른 글

[C/C++] 백준 2863번 이게 분수?  (0) 2020.04.08
[C/C++] 백준 15969번 행복  (0) 2020.04.08
[C/C++] Codeforce 160A - Twins  (0) 2020.04.04
[C/C++] Codeforce 1003C - Intense Heat  (0) 2020.04.04
[C/C++] Codeforce 466C - Number of Ways  (0) 2020.04.04

+ Recent posts