|
| 1 | +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. |
| 2 | +Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook. |
| 3 | + |
| 4 | +Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price |
| 5 | +(if there are multiple such hooks, he chooses any of them). |
| 6 | +However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. |
| 7 | + |
| 8 | +Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, |
| 9 | +all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight. |
| 10 | + |
| 11 | +----------------------------------------- |
| 12 | + |
| 13 | +Sort all the hook prices. |
| 14 | + |
| 15 | +Count the number of unhappy guests = max(guests - hooks, 0) |
| 16 | + |
| 17 | +It it guests - hooks, if guests is greater and 0 if hooks is greater. |
| 18 | + |
| 19 | +All the unhappy guests collect a fine. |
| 20 | + |
| 21 | +-------------------------------------- |
| 22 | + |
| 23 | +int main() |
| 24 | +{ |
| 25 | + int no_of_hooks, fine, no_of_guests; |
| 26 | + scanf("%d %d", &no_of_hooks, &fine); |
| 27 | + |
| 28 | + vector <int> hook_prices(no_of_hooks); |
| 29 | + for(int i = 0; i < no_of_hooks; i++) |
| 30 | + scanf("%d", &hook_prices[i]); |
| 31 | + |
| 32 | + |
| 33 | + sort(all(hook_prices)); |
| 34 | + |
| 35 | + scanf("%d", &no_of_guests); |
| 36 | + |
| 37 | + int unhappy_guests = max(no_of_guests - no_of_hooks, 0); |
| 38 | + int total_fine = unhappy_guests*fine; |
| 39 | + |
| 40 | + int no_of_satisfied_guests = no_of_guests - unhappy_guests; |
| 41 | + int income = 0; |
| 42 | + for(int i = 0; i < no_of_satisfied_guests; i++) |
| 43 | + income += hook_prices[i]; |
| 44 | + |
| 45 | + printf("%d\n", income - total_fine); |
| 46 | + |
| 47 | + return 0; |
| 48 | +} |
0 commit comments