CF261A.Maxim and Discounts

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

There are mm types of discounts. We assume that the discounts are indexed from 1 to mm . To use the discount number ii , the customer takes a special basket, where he puts exactly qiq_{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 qiq_{i} items in the cart.

Maxim now needs to buy nn 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.

输入格式

The first line contains integer mm (1<=m<=105)(1<=m<=10^{5}) — the number of discount types. The second line contains mm integers: q1,q2,...,qmq_{1},q_{2},...,q_{m} (1<=qi<=105)(1<=q_{i}<=10^{5}) .

The third line contains integer nn (1<=n<=105)(1<=n<=10^{5}) — the number of items Maxim needs. The fourth line contains nn integers: a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=104)(1<=a_{i}<=10^{4}) — the items' prices.

The numbers in the lines are separated by single spaces.

输出格式

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

输入输出样例

  • 输入#1

    1
    2
    4
    50 50 100 100
    

    输出#1

    200
    
  • 输入#2

    2
    2 3
    5
    50 50 50 50 50
    

    输出#2

    150
    
  • 输入#3

    1
    1
    7
    1 1 1 1 1 1 1
    

    输出#3

    3
    

说明/提示

In the first sample Maxim needs to buy two items that cost 100100 and get a discount for two free items that cost 5050 . In that case, Maxim is going to pay 200200 .

In the second sample the best strategy for Maxim is to buy 33 items and get 22 items for free using the discount. In that case, Maxim is going to pay 150150 .

首页