CodeForces - 368A Sereja and Coat Rack (水)

CodeForces - 368A
Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

 Status

Description

Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook.

Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest.

Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight.

Input

The first line contains two integers n and d(1 ≤ n, d ≤ 100). The next line contains integers a1a2...an(1 ≤ ai ≤ 100). The third line contains integer m(1 ≤ m ≤ 100).

Output

In a single line print a single integer — the answer to the problem.

Sample Input

Input
2 1
2 1
2
Output
3
Input
2 1
2 1
10
Output
-5
//题意:
在饭店里,有n个衣服架,客人来了要将衣服挂起来,每个衣服架只能挂一件衣服,每个衣服架都有自己的使用费用,所以客人要用就得付费,如果客人来了,衣服架被用完了,那么老板就得给客人d元安慰费,问老板能赚多少钱。
注意:客人来用衣服架都是先找剩下的最便宜的衣服架用(写贪心写惯了,就惯性思维了,开始求的是老板最多赚的钱数,所以就WA了两遍。。。)。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 110
#define M 1000000007
using namespace std; 
int a[N];
int main()
{
	int n,m,d;
	int i,j,k;
	while(scanf("%d%d",&n,&d)!=EOF)
	{
		int s=0;int mm=0;
		for(i=0;i<n;i++)
			scanf("%d",&a[i]),s+=a[i];
		sort(a,a+n);
		scanf("%d",&m);
		if(m==n)
			printf("%d\n",s);
		else if(m<n)
		{
			for(i=0;i<m;i++)
				mm+=a[i];
			printf("%d\n",mm);
		}
		else
			printf("%d\n",s-(m-n)*d);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值