Sereja and Coat Rack(水)
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
Hint
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.
题意:顾客挂衣服,每个称子可以挂一个衣服,每个钩子挂衣服所需要的价格不同,宾客会选便宜的 挂,钩子不够了房东要陪d元,现在有m个顾客,让求今晚房东收益;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
class clothes{
public:
int n,d,m;
int a[];
clothes(int n,int d):n(n),d(d){
for(int i = ; i < n; i++){
cin >> a[i];
}
cin >> m;
}
int work(){
sort(a,a + n);
for(int i = n; i < m; i++)
a[i] = -d;
int ans = ;
for(int i = ; i < m; i++)
ans += a[i];
return ans;
}
};
int main(){
int n,d;
while(~scanf("%d%d", &n, &d)){
clothes _guest(n,d);
cout << _guest.work() << endl;
}
return ;
}
Sereja and Coat Rack(水)的更多相关文章
- Codeforces Round #215 (Div. 2) A. Sereja and Coat Rack
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- codeforces 667B B. Coat of Anticubism(水题)
题目链接: B. Coat of Anticubism time limit per test 1 second memory limit per test 256 megabytes input s ...
- [luogu]P4365[九省联考]秘密袭击coat(非官方正解)
题目背景 警告:滥用本题评测者将被封号 We could have had it all. . . . . . 我们本该,拥有一切 Counting on a tree. . . . . . 何至于此 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- Openjudge 1.13-21:最大质因子序列(每日两水)
总时间限制: 1000ms 内存限制: 65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- Codeforces 刷水记录
Codeforces-566F 题目大意:给出一个有序数列a,这个数列中每两个数,如果满足一个数能整除另一个数,则这两个数中间是有一条边的,现在有这样的图,求最大联通子图. 题解:并不需要把图搞出来, ...
- Bzoj3041 水叮当的舞步
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 132 Solved: 75 Description 水叮当得到了一块五颜六色的格子形地毯作为生日礼物 ...
随机推荐
- HDU4762(JAVA大数)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 对Linux 专家非常有用的20 个命令
谢谢你你给了我们在这篇文章前两个部分的喜欢,美言和支持.在第一部分文章中我们讨论了那些都只是切换到 Linux 和linux新手所需的必要知识的用户的命令. 对 Linux 新手非常有用的 20 个命 ...
- 【转】Android LCD(一):LCD基本原理篇
关键词:android LCD TFT 液晶 偏光片 彩色滤光片 背光 平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:samsung exyno ...
- Hibernate中save、saveorupdate、persist方法的区别
在Hibernate中,save().saveOrUpdate()和persist()都是用于将对象保存到数据库中的方法,但其中有些细微的差别.例如,save()只能INSERT记录,但是saveOr ...
- rabbitmq-c初探
RabbitMQ着实是个好东西,当然了也有对C语言client开发的支持.例子和文档少的可怜,只能去项目里去查看example来理解,简单整理了一些,以免走些弯路.主要是在版本对应上,这点就没Mave ...
- android createbitmap函数内存溢出,求解怎样进行处理out of memory溢出问题
android createbitmap函数内存溢出,求解怎样进行处理out of memory溢出问题 android createbitmap函数内存溢出,求解怎样进行处理out of memor ...
- Linux转发性能评估与优化-转发瓶颈分析与解决方式(补遗)
补遗 关于网络接收的软中断负载均衡,已经有了成熟的方案,可是该方案并不特别适合数据包转发,它对server的小包处理非常好.这就是RPS.我针对RPS做了一个patch.提升了其转发效率. 下面是我转 ...
- Entity Framework 6 Code First创建
基本上我是DB先设计好的,所以就按现存在的table去写程式. 1.Web.config里配置Db连接字串,Connection String Name为DefaultConnection <c ...
- ORACLE集合常用方法
集合方法pl/sql预定义了在varray 和嵌套表实例上进行调用的方法.这些方法能在集合上执行一定的功能. EXISTS 该函数返回集合中第一个元素的索引,如果集合为空,返回NULL Collect ...
- 前端-mate讲解
<meta> 元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. <meta> 标签位于文档的头部,不包含任何内容. & ...