1132 B. Discounts by mrhao61

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool cmp(long long int a,long long int b)
{
	return a>b;
}
int main()
{
	long long int n,m;cin>>n;
	vector<int>a,b;
	long long int sum=0;
	for(long long int i=0;i<n;i++)
	{
		long long int x;cin>>x;
		a.push_back(x);
		sum=sum+x;
	}
	cin>>m;
	for(long long int i=0;i<m;i++)
	{
		long long int x;cin>>x;
		b.push_back(x);
	}
	sort(a.begin(),a.end(),cmp);
	for(long long int i=0;i<m;i++)
	{
		cout<<sum-a[b[i]-1]<<endl;
	}
}

B. Discounts
time limit per test2.5 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs ai coins (and you want to buy all of them).

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

You can use only one coupon; if you use coupon i, you have to choose qi bars and buy them using the coupon, and buy all the remaining n−qi 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 n (2≤n≤3⋅105) — the number of chocolate bars in the shop.

The second line contains n integers a1, a2, …, an (1≤ai≤109), where ai is the cost of i-th chocolate bar.

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

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

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

Example
inputCopy
7
7 1 3 1 4 10 8
2
3 4
outputCopy
27
30
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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值