#P6002. [USACO20JAN] Berry Picking S
[USACO20JAN] Berry Picking S
Problem Description
Bessie and her sister Elsie are picking berries in Farmer John's berry orchard. There are berry trees in the orchard (). Tree has berries (). Bessie has baskets (, and is even). Each basket can hold any number of berries picked from the same tree, but it cannot contain berries from different trees, because they may taste different. A basket may also be left empty.
Bessie wants to maximize the number of berries she gets. However, Farmer John wants Bessie to share with her sister, so Bessie must give the baskets with more berries to Elsie. This means Elsie may end up with more berries than Bessie, which is unfair, but that is often how sisters are.
Help Bessie find the maximum number of berries she can get.
Input Format
The first line contains the space-separated integers and .
The second line contains space-separated integers .
Output Format
Output one line with the answer.
5 4
3 6 8 4 2
8
Hint
Sample Explanation
If Bessie puts:
- 6 berries from tree 2 into one basket,
- 4 berries from tree 3 into each of two baskets,
- 4 berries from tree 4 into one basket,
then she can get two baskets with 4 berries each, for a total of 8 berries.
Subtasks
- Test cases satisfy .
- Test cases have no additional constraints.
Translated by ChatGPT 5