codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

368A.md (1673B)


      1 Source: https://codeforces.com/problemset/problem/368/A
      2 
      3 A. Sereja and Coat Rack
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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 *a**i* rubles. Only one person can hang clothes on one hook.
     22 
     23 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.
     24 
     25 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.
     26 
     27 Input
     28 
     29 The first line contains two integers *n* and *d* (1 ≤ *n*, *d* ≤ 100). The next line contains integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 100). The third line contains integer *m* (1 ≤ *m* ≤ 100).
     30 
     31 Output
     32 
     33 In a single line print a single integer — the answer to the problem.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 2 1  
     41 2 1  
     42 2
     43 ```
     44 
     45 Output
     46 
     47 ```
     48 3
     49 ```
     50 
     51 Input
     52 
     53 ```
     54 2 1  
     55 2 1  
     56 10
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 -5
     63 ```
     64 
     65 Note
     66 
     67 In the first test both hooks will be used, so Sereja gets 1 + 2 = 3 rubles.
     68 
     69 In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3 - 8 =  - 5.