CF261A.Maxim and Discounts

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

麦克斯姆总是在周日去超市购物。今天超市推出了一种特殊的折扣系统。

共有 mm 种折扣类型,我们假设这些折扣从 11 编号至 mm。要使用第 ii 种折扣,顾客需取一个特制购物篮,并将恰好 qiq_i 件待购商品放入其中。根据该折扣规则,除篮中商品外,顾客最多还可从超市免费获得 2 件 商品(即免费商品数量可为 00、11 或 22),具体数量由顾客自行选择。对所选免费商品的唯一限制是:每件免费商品的价格均不得超过篮中 qiq_i 件商品里最便宜那件的价格。

目前麦克斯姆需要在超市购买 nn 件商品。若他能最优地利用该折扣系统,求他所需支付的最少金额。

请假设超市拥有足够多的购物篮以支持任意操作;麦克斯姆可多次使用同一种折扣;当然,他也可以选择不使用任何折扣直接购买商品。

输入格式

The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: _q_1, _q_2, ..., q__m (1 ≤ q__i ≤ 105).

The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 104) — the items' prices.

The numbers in the lines are separated by single spaces.

第一行包含一个整数 mm(1≤m≤1051 \leq m \leq 10^5)—— 折扣类型的数量。
第二行包含 mm 个整数:q1, q2, …, qmq_1,\,q_2,\,\dots,\,q_m(1≤qi≤1051 \leq q_i \leq 10^5)。

第三行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— Maxim 所需物品的数量。
第四行包含 nn 个整数:a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n(1≤ai≤1041 \leq a_i \leq 10^4)—— 各物品的价格。

每行中的数字以单个空格分隔。

输出格式

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.

在第一个样例中,马克西姆需要购买两件价格为 100 的商品,并获得两件价格为 50 的商品的免费折扣。此时,马克西姆需支付 200。

在第二个样例中,马克西姆的最优策略是购买 3 件商品,并利用折扣免费获得 2 件商品。此时,马克西姆需支付 150。

输入解题思路,AI测评打分。不知道怎么写?

首页