CF1132B.Discounts

入门

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

You came to a local shop and want to buy some chocolate bars. There are nn bars in the shop, ii-th of them costs aia_i coins (and you want to buy all of them).

You have mm different coupons that allow you to buy chocolate bars. ii-th coupon allows you to buy qiq_i chocolate bars while you have to pay only for the qi−1q_i - 1 most expensive ones (so, the cheapest bar of those qiq_i bars is for free).

You can use only one coupon; if you use coupon ii, you have to choose qiq_i bars and buy them using the coupon, and buy all the remaining n−qin - q_i bars without any discounts.

To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

你来到一家本地商店,想购买一些巧克力棒。店里共有 nn 根巧克力棒,其中第 ii 根的价格为 aia_i 枚硬币(你打算全部买下)。

你手上有 mm 张不同的优惠券,可用于购买巧克力棒。第 ii 张优惠券允许你购买 qiq_i 根巧克力棒,但你只需支付其中最贵的 qi−1q_i - 1 根的价格(即这 qiq_i 根中最便宜的一根免费)。

你最多只能使用一张优惠券;若使用第 ii 张优惠券,则必须从中挑选出恰好 qiq_i 根巧克力棒并用该优惠券购买,其余 n−qin - q_i 根则需按原价全额购买,不享受任何折扣。

为了决定选择哪张优惠券,你想知道:若恰当地使用其中一张优惠券,你所需支付的最少总金额是多少?

输入格式

The first line contains one integer nn (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5) — the number of chocolate bars in the shop.

The second line contains nn integers a1a_1, a2a_2, ..., ana_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i is the cost of ii-th chocolate bar.

The third line contains one integer mm (1≤m≤n−11 \le m \le n - 1) — the number of coupons you have.

The fourth line contains mm integers q1q_1, q2q_2, ..., qmq_m (2≤qi≤n2 \le q_i \le n), where qiq_i is the number of chocolate bars you have to buy using ii-th coupon so that the least expensive of them will be for free. All values of qiq_i are pairwise distinct.

第一行包含一个整数 nn(2≤n≤3⋅1052 \le n \le 3 \cdot 10^5)—— 商店中巧克力棒的数量。

第二行包含 nn 个整数 a1a_1, a2a_2, ..., ana_n(1≤ai≤1091 \le a_i \le 10^9),其中 aia_i 表示第 ii 根巧克力棒的价格。

第三行包含一个整数 mm(1≤m≤n−11 \le m \le n - 1)—— 你拥有的优惠券数量。

第四行包含 mm 个整数 q1q_1, q2q_2, ..., qmq_m(2≤qi≤n2 \le q_i \le n),其中 qiq_i 表示使用第 ii 张优惠券时需购买的巧克力棒数量,此时其中最便宜的一根将免费。所有 qiq_i 的值两两不同。

输出格式

Print mm integers, ii-th of them should be the minimum amount of money you have to pay if you buy qiq_i bars with ii-th coupon, and all the remaining bars one by one for their full price.

输出 mm 个整数,其中第 ii 个整数表示:使用第 ii 个优惠券购买 qiq_i 块巧克力,并以全价逐一购买其余所有巧克力时,所需支付的最少金额。

输入输出样例

  • 输入#1

    7
    7 1 3 1 4 10 8
    2
    3 4

    输出#1

    27
    30

说明/提示

Consider the first example.

If we use the first coupon, we may choose chocolate bars having indices 11, 66 and 77, and we pay 1818 coins for them and 99 coins for all other bars.

If we use the second coupon, we may choose chocolate bars having indices 11, 55, 66 and 77, and we pay 2525 coins for them and 55 coins for all other bars.

考虑第一个例子。

如果我们使用第一张优惠券,可以选择索引为 11、66 和 77 的巧克力棒,为此支付 1818 枚金币,其余所有巧克力棒支付 99 枚金币。

如果我们使用第二张优惠券,可以选择索引为 11、55、66 和 77 的巧克力棒,为此支付 2525 枚金币,其余所有巧克力棒支付 55 枚金币。

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

首页