B. Discounts

地址:https://codeforces.com/contest/1132/problem/B

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

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

You can use only one coupon; if you use coupon ?, you have to choose ?? bars and buy them using the coupon, and buy all the remaining ?−?? 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.

Input
The first line contains one integer ? (2≤?≤3⋅105) — the number of chocolate bars in the shop.

The second line contains ? integers ?1, ?2, …, ?? (1≤??≤109), where ?? is the cost of ?-th chocolate bar.

The third line contains one integer ? (1≤?≤?−1) — the number of coupons you have.

The fourth line contains ? integers ?1, ?2, …, ?? (2≤??≤?), where ?? is the number of chocolate bars you have to buy using ?-th coupon so that the least expensive of them will be for free. All values of ?? are pairwise distinct.

Output
Print ? integers, ?-th of them should be the minimum amount of money you have to pay if you buy ?? bars with ?-th coupon, and all the remaining bars one by one for their full price.
inputCopy
在这里插入图片描述
Note
Consider the first example.

If we use the first coupon, we may choose chocolate bars having indices 1, 6 and 7, and we pay 18 coins for them and 9 coins for all other bars.

If we use the second coupon, we may choose chocolate bars having indices 1, 5, 6 and 7, and we pay 25 coins for them and 5 coins for all other bars.

请注意
考虑第一个例子。
如果我们使用第一张优惠券,我们可以选择指数为1、6和7的巧克力棒,我们为它们支付18个硬币,为所有其他巧克力棒支付9个硬币。
如果我们使用第二张优惠券,我们可以选择指数为1、5、6和7的巧克力棒,我们为它们支付25个硬币,为所有其他巧克力棒支付5个硬币。

一般看有道就可以直接做了。
之前a[],b[]里面数据不够大,然后就…在这里插入图片描述

在这里插入图片描述
然后把a[]改大了就过了。
emmm,有点迷。

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;


int main()
{
	long long int n, m, i,num, sum;
	long long int a[10000000], b[1000000] = { 0 };
	cin >> n;
	sum = 0;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	num = sum;
	cin >> m;
	sort(a, a + n);
	for (i = 0; i < m; i++)
		cin >> b[i];
	for (i = 0; i < m; i++)
	{
		num=sum- a[n - b[i]];
		cout <<num<< endl;
	}
	//system("pause");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值