301391: CF261A. Maxim and Discounts

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Maxim and Discounts

题意翻译

Maxim 每个星期天都会去超市购物,今天超市有一些特别的打折方式 超市一共推出了 $m$ 种打折方式。我们将这m种打折方式编号为 $1$ ~ $m$ 。 在选择第i种打折方式时,购物者必须用超市提供的手推车严格购买 $q_i$ 个物品。当然,超市的手推车是很多的,我们可以认为有无穷多个手推车。每用一次任意一种打折方式,购物者就可以选择2件其他物品免费带走。对于这两件物品唯一的要求就是他们的价格的最大值不能大于购买的 $q_i$ 个物品中的价格的最小值。 Maxim 现在要去超市购买 $n$ 个物品。请你计算出 Maxim 买这 $n$ 个物品最少要花多少钱。 Maxim 可以多次使用同一个打折方式,当然,他也可以不使用任何打折方式。 输入共4行,第一行包括一个整数 $m$ ,表示一共有 $m$ 种打折方式。 第二行包括 $m$ 个整数,第 $i$ 个数 $q_i$ 表示第 $i$ 种打折方式需要购买 $q_i$ 个物品 第三行包括1个整数 $n$ 第四行包括 $n$ 个整数,表示 Maxim 需要购买的 $n$ 个物品

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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 $ 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

题意翻译

Maxim 每个星期天都会去超市购物,今天超市有一些特别的打折方式 超市一共推出了 $m$ 种打折方式。我们将这m种打折方式编号为 $1$ ~ $m$ 。 在选择第i种打折方式时,购物者必须用超市提供的手推车严格购买 $q_i$ 个物品。当然,超市的手推车是很多的,我们可以认为有无穷多个手推车。每用一次任意一种打折方式,购物者就可以选择2件其他物品免费带走。对于这两件物品唯一的要求就是他们的价格的最大值不能大于购买的 $q_i$ 个物品中的价格的最小值。 Maxim 现在要去超市购买 $n$ 个物品。请你计算出 Maxim 买这 $n$ 个物品最少要花多少钱。 Maxim 可以多次使用同一个打折方式,当然,他也可以不使用任何打折方式。 输入共4行,第一行包括一个整数 $m$ ,表示一共有 $m$ 种打折方式。 第二行包括 $m$ 个整数,第 $i$ 个数 $q_i$ 表示第 $i$ 种打折方式需要购买 $q_i$ 个物品 第三行包括1个整数 $n$ 第四行包括 $n$ 个整数,表示 Maxim 需要购买的 $n$ 个物品

加入题单

算法标签: