#P1528. 切蛋糕

    ID: 519 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索贪心深度优先搜索,DFS剪枝

切蛋糕

Description

Facer bought nn cakes today. Unfortunately, the lazy gluttons in the Information Group, including Qiuqiu, found out. He had no choice but to spare some to feed them. He promised to leave one bite for everyone and measured the size of each person's mouth. Facer has a knife and can cut cakes, but he cannot combine two cakes into one serving, and he will not give anyone two cakes. Now, how should Facer cut the cakes to satisfy the maximum number of people? (Facer's knife is perfect; cutting does not waste any cake.)

Input Format

The first line contains nn, the number of cakes Facer has.
Each of the next nn lines contains the size of a cake.
The next line contains mm, the number of people in the Information Group.
Each of the next mm lines contains one number, the size of a person's mouth.
Constraints: 1n501 \le n \le 50, 1m10241 \le m \le 1024.

Output Format

One line: the maximum number of mouths Facer can fill.

4
30
40
50
25
10
15
16
17
18
19
20
21
25
24
30

 

7

Hint

Translated by ChatGPT 5