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 水叮当得到了一块五颜六色的格子形地毯作为生日礼物 ...
随机推荐
- HDU1506(单调栈或者DP) 分类: 数据结构 2015-07-07 23:23 2人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 2013长沙网络赛H题Hypersphere (蛋疼的题目 神似邀请赛A题)
Hypersphere Time Limit: 1 Second Memory Limit: 32768 KB In the world of k-dimension, there's a ...
- PHP 9 大缓存技术总结
1.全页面静态化缓存 也就是将页面全部生成html静态页面,用户访问时直接访问的静态页面,而不会去走php服务器解析的流程.此种方式,在CMS系统中比较常见,比如dedecms: 一种比较常用的实现方 ...
- Java 线程第三版 第八章 Thread与Collection Class 读书笔记
JDK1.2引入最有争议性的改变是将集合类默觉得不是Thread安全性的. 一.Collection Class的概述 1. 具有Threadsafe 的Collection Class: j ...
- 加载本地html遇到的问题
之前要做一个Demo,需要用UIWebView来加载网页,前端的同事把资源包给我,里面包含html,css,JavaScript,图片等文件.我想当然的把文件夹拷到工程中,然后用以下方法加载: NSU ...
- pl/sql连接远程服务器
1.oracle提供了instantclient,下载instantclient-basic-win32-10.2.0.4.zip,将包解压存放到本地,如:D:\STUDY\instantclient ...
- jQuery日期和时间插件(jquery-ui-timepicker-addon.js)中文破解版使用
<html> <head> <title></title> <link type="text/css" href=" ...
- 生成shadow中hash字串
[root@master base]# openssl passwd -1 -salt 123Password: $1$123$2rm.J6pr3p.rmj6YoKSQ8.[root@master b ...
- 关于meta定义 和 link
<!DOCTYPE html> <!-- HTML5 doctype 不区分大小写 --> <html lang="zh-cmn-Hans-CN"&g ...
- php微信公众帐号发送红包
开发框架为we7 所需参数:appid,appSecret,MchId,API密钥 <?php /** * 微信红包的类 * */ CLASS WXHongBao { private $mch_ ...