Time Limit: 1000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
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 a1, a2, ..., 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
2 1 2 1 2
3
2 1 2 1 10
-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; }