Codeforces 215A A.Sereja and Coat Rack

来源:互联网 发布:手机摄影软件 编辑:程序博客网 时间:2024/05/16 14:29
A. Sereja and Coat Rack
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
2 12 12
output
3
input
2 12 110
output
-5
Note

In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles.

In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 =  - 5.


代码:


#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#define INF 0x3f3f3f3fusing namespace std;int main(){int n,d,a[110],m,pay,i,sum,k;while(scanf("%d%d",&n,&d)!=EOF){sum=0;    for(i=0;i<n;i++){    scanf("%d",&a[i]);}scanf("%d",&m);sort(a,a+n);k=min(n,m);for(i=0;i<k;i++){sum+=a[i];}//printf("%d\n",sum);if(m>n)pay=(m-n)*d;elsepay=0;printf("%d\n",sum-pay);} return 0;} 


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 卧蚕眼袋都有怎么办 3个月宝宝眉毛淡怎么办 1个月宝宝眉毛淡怎么办 我眉毛很淡又少怎么办 脸两侧颧骨太宽怎么办 脸的两边太宽怎么办 脸宽怎么办可以瘦下来 白眼球红了一块怎么办 三国志13坏档了怎么办 权倾三国的战车怎么办 勾线笔笔头干了怎么办 水彩笔没有水了怎么办 水彩笔不出水了怎么办 去眼袋后有皱纹怎么办 一笑眼角有皱纹怎么办 打了玻尿酸淤青怎么办 眉头两边长痘痘怎么办 下巴和额头长痘怎么办 额头上一直长痘怎么办 额头上的闭合性粉刺怎么办 脸上有多长痘痘怎么办 雄性激素过多长痘痘怎么办 额头上反复长痘怎么办 汽车脱审一个月怎么办 山药弄到手上痒怎么办 山药弄到皮肤痒怎么办 喉咙痒咳嗽痰多怎么办 老赖2年后仍不还怎么办 老赖欠款不还怎么办 酒店丢了房卡怎么办 微信上买狗被骗怎么办 洋码头不给退货怎么办 代购被海关查了怎么办 洋码头被投诉了怎么办 安利网上办卡怎么办 美图m6拍照模糊怎么办 买的发箍戴着紧怎么办 带发卡老是滑掉怎么办 发卡戴不住总滑怎么办 皮肤皮肤干燥起皮怎么办 拔毒膏拔出脓后怎么办