Codeforces 215A A.Sereja and Coat Rack
来源:互联网 发布:手机摄影软件 编辑:程序博客网 时间:2024/05/16 14:29
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.
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).
In a single line print a single integer — the answer to the problem.
2 12 12
3
2 12 110
-5
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;}
- CodeForces 368A Sereja and Coat Rack
- Codeforces 215A A.Sereja and Coat Rack
- Codeforces Round #215 (Div. 2) -A. Sereja and Coat Rack
- Codeforces Round #215 (Div. 2) A. Sereja and Coat Rack
- A. Sereja and Coat Rack
- Codeforces 368A Sereja and Coat Rack(模拟)
- CodeForces - 368A Sereja and Coat Rack (水)
- CodeForces 368A-Sereja and Coat Rack【队列】
- CodeForces 368A:Sereja and Coat Rack【水】
- CF#215DIV2:A. Sereja and Coat Rack
- I - Sereja and Coat Rack
- codeforce Sereja and Coat Rack(简单排序)
- codeforces --A - Sereja and Algorithm
- Sereja and Algorithm -----Codeforces Round #215 div.1 A
- 【瞎搞】 Codeforces Round #215 (Div. 1) A Sereja and Algorithm
- CodeForces 315A Sereja and Bottles
- Codeforces 380 A. Sereja and Prefixes
- Codeforces 367A Sereja and Algorithm
- 在JLabel上显示图片,并且图片自适应JLabel的大小
- QT 的单选按钮使用方法
- VS2010测试功能之旅:编码的UI测试(1)
- java Object类及其常用方法
- leetcode 46. Permutations
- Codeforces 215A A.Sereja and Coat Rack
- mongoDB——read&write操作
- 杭电5640 King's Cake
- python勿使用mutable值作为默认参数
- notePad++快捷键用法
- centos忘记root密码,重新设置的方法
- leetcode_023 Merge k Sorted Lists
- java项目——提升网站性能之java模板引擎beetl
- 网络基础:子网掩码划分2