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 水叮当得到了一块五颜六色的格子形地毯作为生日礼物 ...
随机推荐
- ZOJ3414Trail Walk(计算几何)
Trail Walk Time Limit: 2 Seconds Memory Limit: 65536 KB FatMouse is busy organizing the coming ...
- HttpURLConnection访问url的工具类
java代码: import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; ...
- Linux转发性能评估与优化-转发瓶颈分析与解决方式(补遗)
补遗 关于网络接收的软中断负载均衡,已经有了成熟的方案,可是该方案并不特别适合数据包转发,它对server的小包处理非常好.这就是RPS.我针对RPS做了一个patch.提升了其转发效率. 下面是我转 ...
- Android项目实战-云词典
前段时间在网上看到滴答滴答的一个项目,字典文章,找到一个简单的字.整句翻译功能,词汇,但漫长的岁月项目,二手API数据不再可用,我决定使用其现有的框架来实现其功能,主要采用的技术GSON和Volley ...
- 【转】关于ios10中ATS的问题
原文连接:https://onevcat.com/2016/06/ios-10-ats/ WWDC 15 提出的 ATS (App Transport Security) 是 Apple 在推进网络通 ...
- OC——动态添加Button和监听UIAlertView按钮
1:动态添加uibutton - (IBAction)addButton:(id)sender { CGRect frame = CGRectMake(90, 200, 200, 60); UIBut ...
- JSP总结2 配置开发环境和firstjsp
JDK的下载 JAVA_HOME ,CLASSPATH,PATH 的配置,根据安装路径. 然后java -version检测配置OK. 编写helloworld.java 放置在同JDK 盘里.j ...
- stl的集合set——安迪的第一个字典(摘)
set就是数学上的集合——每个元素最多只出现一次,和sort一样,自定义类型也可以构造set,但同样必须定义“小于”运算符 以下代码测试set中无重复元素 #include<iostream&g ...
- android学习—should use @string resource警告
在布局文件中,文本的设置使用如下写法时会有警告:Hardcoded string "BUTTON", should use @string resource <Button ...
- 日志管理-NLog日志框架简写用法
本文转载:http://www.blogjava.net/qiyadeng/archive/2013/02/27/395799.html 在.net中也有非常多的日志工具,今天介绍下NLog.NLog ...