#P15091. [UOI 2025 II Stage] Catamarans

[UOI 2025 II Stage] Catamarans

题目描述

A group of nn people plans to go for a ride on catamarans.

As the leader of the group, you have been tasked with ordering the catamarans. You know that one catamaran can hold a weight of no more than 100100 kilograms, and you also know the weight of each group member.

You are aware that in your group, a person can weigh either 2020, 4040, 6060, 8080, or 100100 kilograms.

To spend as little money as possible, you decided to write a program that calculates the minimum number of catamarans needed.

输入格式

The first line contains one integer nn (1n1000)(1 \le n \le 1\,000)~--- the number of people in the group.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (ai{20,40,60,80,100})(a_i \in \{20, 40, 60, 80, 100\})~--- the weight of each person.

输出格式

Output one integer --- the minimum number of catamarans needed.

4
20 40 80 80
3
4
20 40 20 20
1

提示

In the first example, we can seat the first two people in one catamaran, the third person in the second catamaran, and the fourth person in the third catamaran. We cannot seat everyone in two catamarans because person 22 cannot sit with person 33 or 44, and person 33 cannot sit with person 44 either.

In the second example, we can seat everyone in one catamaran because their total weight is equal to 100100 kilograms, which means the catamaran can hold them.