logo AlgoBeat OnlineJudge
登录 注册

#217651. [ECNA 2025] A Little Leftover Pizza

内存限制:2048 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

The CS department has just had a big party and ordered too much pizza. Now it is time to put away the leftovers. They ordered a number of small, medium, and large pizzas, and there are still slices remaining in some or all of the pizza boxes. A small pizza comes in 6 slices, a medium pizza in 8 slices, and a large pizza in 12 slices. To save space, you can combine the leftover slices from the same size pizzas into a box of the right size, but you can't put a slice into a box for a different sized pizza, and you can't put more slices into a box than it originally held. What is the smallest number of boxes you will need to hold all the leftovers?

输入格式

The first line of input contains one positive integer (), the number of pizzas that were ordered. Each of the following lines contains two items and (separated by a space) representing the leftovers for a given pizza. is a string S, M, or L representing the size of pizza , and is an integer representing the number of leftover slices for pizza . You can assume that each is between zero and the original number of slices of that size pizza, inclusive.

输出格式

Output a single number, the fewest possible total boxes that can hold the leftover pizza according to the constraints given above.

样例

样例输入 1

3
S 0
M 5
L 0

样例输出 1

1

样例输入 2

3
S 3
S 4
S 2

样例输出 2

2

样例输入 3

4
S 1
M 1
M 3
L 1

样例输出 3

3

样例输入 4

4
L 6
M 2
M 6
L 6

样例输出 4

2