Codeforces Round 160 (Div. 2)
C
Maxim and Discounts
Codeforces
未评级
原题
← BD →
翻译中…

Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.

翻译中…

There are $*m*$ types of discounts. We assume that the discounts are indexed from 1 to $*m*$. To use the discount number $*i*$, the customer takes a special basket, where he puts exactly $*q*_{*i*}$ items he buys. Under the terms of the discount system, in addition to the items in the cart the customer can receive at most two items from the supermarket for free. The number of the "free items" (0, 1 or 2) to give is selected by the customer. The only condition imposed on the selected "free items" is as follows: each of them mustn't be more expensive than the cheapest item out of the $*q*_{*i*}$ items in the cart.

翻译中…

Maxim now needs to buy $*n*$ items in the shop. Count the minimum sum of money that Maxim needs to buy them, if he use the discount system optimally well.

翻译中…

Please assume that the supermarket has enough carts for any actions. Maxim can use the same discount multiple times. Of course, Maxim can buy items without any discounts.

翻译中…

Input

翻译中…

The first line contains integer $*m*$ $(1 ≤ *m* ≤ 10^{5})$ — the number of discount types. The second line contains $*m*$ integers: $*q*_{1}, *q*_{2}, ..., *q*_{*m*}$ $(1 ≤ *q*_{*i*} ≤ 10^{5})$.

翻译中…

The third line contains integer $*n*$ $(1 ≤ *n* ≤ 10^{5})$ — the number of items Maxim needs. The fourth line contains $*n*$ integers: $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ $(1 ≤ *a*_{*i*} ≤ 10^{4})$ — the items' prices.

翻译中…

The numbers in the lines are separated by single spaces.

翻译中…

Output

翻译中…

In a single line print a single integer — the answer to the problem.

翻译中…

Note

翻译中…

In the first sample Maxim needs to buy two items that cost $100$ and get a discount for two free items that cost $50$. In that case, Maxim is going to pay $200$.

翻译中…

In the second sample the best strategy for Maxim is to buy $3$ items and get $2$ items for free using the discount. In that case, Maxim is going to pay $150$.

翻译中…

样例

Input #1
1
2
4
50 50 100 100
Output #1
200
InputCopy OutputCopy
Input #2
2
2 3
5
50 50 50 50 50
Output #2
150
InputCopy OutputCopy
Input #3
1
1
7
1 1 1 1 1 1 1
Output #3
3
InputCopy OutputCopy
题目信息
题号
262C
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。