• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #215 Div2 A

A. Sereja and Coat Rack
time limit per test 1 second
memory limit per test 256 megabytes
 

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 test(s)
Input
2 1 
2 1
2
Output
3
Input
2 1 
2 1
10
Output
-5
Note

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.

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <vector>
 4 #include <set>
 5 #include <cstring>
 6 #include <string>
 7 #include <map>
 8 #include <cmath>
 9 #include <ctime>
10 #include <algorithm>
11 #include <queue>
12 
13 using namespace std;
14 #define INF 0x7fffffff
15 #define maxm 1001
16 #define mp make_pair
17 #define pb push_back
18 #define rep(i,n) for(int i = 0; i < (n); i++)
19 #define re return
20 #define fi first
21 #define se second
22 #define sz(x) ((int) (x).size())
23 #define all(x) (x).begin(), (x).end()
24 #define sqr(x) ((x) * (x))
25 #define sqrt(x) sqrt(abs(x))
26 #define y0 y3487465
27 //#define y1 y8687969
28 //#define fill(x,y) memset(x,y,sizeof(x))
29 
30 typedef vector<int> vi;
31 typedef long long ll;
32 typedef long double ld;
33 typedef double D;
34 typedef pair<int, int> ii;
35 typedef vector<ii> vii;
36 typedef vector<string> vs;
37 typedef vector<vi> vvi;
38 
39 template<class T> T abs(T x) { re x > 0 ? x : -x; }
40 
41 const int maxn = 110005;
42 
43 int n, m, t, s, k, x;
44 int a[maxn], b[maxn];
45 int main(){
46     scanf("%d%d", &n, &k);
47     for (int i = 0; i < n; i++)scanf("%d", &a[i]);
48     scanf("%d", &m);
49     sort(a, a + n);
50     s = 0;
51     if (m<n)
52     for (int i = 0; i < m; i++)s += a[i];
53     else for (int i = 0; i < n; i++)s += a[i];
54     if (m>n)s -= (m - n)*k;
55     printf("%d\n", s);
56     return 0;
57 }
View Code
posted @ 2013-11-27 01:44  HaibaraAi  阅读(158)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3