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 水叮当得到了一块五颜六色的格子形地毯作为生日礼物 ...
随机推荐
- 百度地图LV1.5实践项目开发工具类bmap.util.jsV1.1
/** * 百度地图使用工具类-v1.5 * * @author boonya * @date 2013-7-7 * @address Chengdu,Sichuan,China * @email b ...
- GridBagLayout练习
摘自http://blog.csdn.net/qq_18989901/article/details/52403737 GridBagLayout的用法 GridBagLayout是面板设计中最复杂 ...
- struts2复习(五)拦截器总结
1. 拦截器(Interceptor): 拦截器是Struts2的核心,Struts2的众多功能都是通过拦截器来实现的. 2. 拦截器的配置 1)编写实现Interceptor 接口的类. 2)在s ...
- UVA 246 - 10-20-30 (模拟+STL)
UVA 246 - 10-20-30 题目链接 题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,假设有牌堆形成了下面3种情况(按顺序推断): 1.头两张+尾一张和为10或20 ...
- RMAN完整全备份
1.以CATALOG模式连接到目标数据库和恢复目录(如:目标数据库为ORCL) C:\Users\Administrator>RMAN TARGET / CATALOG RMANCT/RMANC ...
- js判断是否安装flash
<script type="text/javascript"> (function () { var noFlash = "你的浏览器没有安装Flash,会影 ...
- (原创) C# List 找 Max 的 Index
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 查看DB文件的空间使用情况
可以使用如下语句获得DB文件的空间使用 use dbName SELECT DB_NAME() AS DbName, name AS FileName, size/128.0 AS CurrentSi ...
- (重要) html概念之 input:name与id详解
实例: 带有两个文本字段和一个提交按钮的 HTML 表单: <form action="form_action.asp" method="get"> ...
- Debian 使用杂记(一)
前几天又冲动的把系统换成Linux了,最开始接触Linux是2010年,那时候买了个本本,预装的是ubuntu8.10,自此知道除了windows原来还有其它操作系统. 不记得什么时候开始知道ubun ...