eolymp
bolt
Try our new interface for solving problems
Problems

Berry Picking

Berry Picking

Bessie and her little sister Elsie are picking berries in Farmer John's berry patch. Farmer John's patch has exactly $n$ berry trees; tree $i$ contains exactly $b_i$ berries. Bessie has exactly $k$ baskets. Each basket can hold as many berries from a single tree as Bessie wants, but cannot contain berries from two different trees as their flavours will clash with each other. Baskets may remain empty. Bessie wants to maximize the number of berries she collects. However, Farmer John wants Bessie to share with her little sister, and so Bessie will have to give Elsie the $k / 2$ baskets with the largest number of berries. This means that Elsie may even end up with more berries than Bessie, which is very unfair, but unfortunately, sibling dynamics are not always fair. Help Bessie figure out the maximum number of berries she can collect. \InputFile The first line contains space separated integers $n\:(1 \le n \le 1000)$ and $k\:$($1 \le k \le 1000, k$ is even). The second line contains $n$ integers $b_1, b_2, ..., b_n\:(1 \le b_i \le 1000)$. \OutputFile Print the maximum number of berries Bessie can collect. \Note If Bessie fills \begin{itemize} \item one basket with $6$ berries from tree $\:2$ \item two baskets, each with $4$ berries from tree $\:3$ \item one basket with $4$ berries from tree $\:4$ \end{itemize} then she receives two baskets each with $4$ berries, giving her $8$ berries in total.
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 4
3 6 8 4 2
Output example #1
8
Source 2020 USACO January Silver