I - Sereja and Coat Rack

简介: I - Sereja and Coat Rack


 

I - Sereja and Coat Rack

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

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

Input

2 1
2 1
2

Output

3

Input

2 1
2 1
10

Output

-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.

 

 

 

 

题目分析:

没有什么难度,意思就是

2 1

2 1

10

一个小饭馆有2个衣架如果有客人来没有衣架了那么老板就要给客人1块钱补偿

第二行   是每个衣架使用的费用,

第三行就是  来的客人总数

注意:注意先来的客人肯定是选最便宜的衣架了,你懂的,如果是你你不选便宜的吗?

 

 

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
  int n,k,m;
  int a[1100];
  while(~scanf("%d%d",&n,&k))
  {
    for(int i=0;i<n;i++)
      scanf("%d",&a[i]);
    scanf("%d",&m);
    sort(a,a+n);
//    for(int i=1;i<=n;i++)
//      printf("%d ",a[i]);
//      printf("\n");
    int cost=0;
    if(m<=n)
    {
      for(int i=0;i<m;i++)
        cost+=a[i];
    }
    else
    {
      for(int i=0;i<n;i++)
        cost+=a[i];
      cost-=(m-n)*k; 
    }
    //if(m==0) cost=0;
    printf("%d\n",cost);
  }
  return 0;
}

 

 

 

 

 


目录
相关文章
|
弹性计算 应用服务中间件
现在购买阿里云服务器需要多少钱?不同预算可购买的配置汇总
个人和企业用户由于上云场景不同,购买阿里云服务器的预算也同,一般来说用户购买阿里云服务器的预算主要集中在100元以内、100-500元、500-1000元、1000-3000元和3000元以上这几个等级。来看下这些预算可以买到什么实例和配置的阿里云服务器。
994 0
现在购买阿里云服务器需要多少钱?不同预算可购买的配置汇总
|
3天前
|
存储 关系型数据库 分布式数据库
PostgreSQL 18 发布,快来 PolarDB 尝鲜!
PostgreSQL 18 发布,PolarDB for PostgreSQL 全面兼容。新版本支持异步I/O、UUIDv7、虚拟生成列、逻辑复制增强及OAuth认证,显著提升性能与安全。PolarDB-PG 18 支持存算分离架构,融合海量弹性存储与极致计算性能,搭配丰富插件生态,为企业提供高效、稳定、灵活的云数据库解决方案,助力企业数字化转型如虎添翼!
|
14天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1305 5
|
13天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
1332 87
|
2天前
|
弹性计算 安全 数据安全/隐私保护
2025年阿里云域名备案流程(新手图文详细流程)
本文图文详解阿里云账号注册、服务器租赁、域名购买及备案全流程,涵盖企业实名认证、信息模板创建、域名备案提交与管局审核等关键步骤,助您快速完成网站上线前的准备工作。
184 82
2025年阿里云域名备案流程(新手图文详细流程)