There are total N suppliers. Each suppliers has arr[i] products. Every time a product sold the supplier will raise the price by 1. And your profit on any product is equals to the number of products the supplier has left. Your job is to buy K products from N suppliers and make the highest profit.

**Input**

N, an integer representing the number of suppliers;

arr, a list of long integers representing the supply of the ith supplier;

K, a long integer representing the number of items to be ordered.

**Output**

Return a long integer representing the highest profit that can be generated.

**Constraints**

1 <= N <= 100,000

1 <= arr[i] <= 100,000

0 <= i < N

1 <= K <= sum of arr

**Example1**:

Input:

N = 2

arr = [3, 4]

K = 6

Output:

15

Explanation:

Here supplier one has 3 products. The final prices are [3, 2, 1].

Here supplier two has 4 products. The final prices are [4, 3, 2, 1]

The highest profit is 4 + 2 * 3 + 2 * 2 + 1 = 15

**Example2**:

Input:

N = 5

arr = [3, 5, 7, 10, 6]

K = 20

Output:

107

Explanation:

(Green = available, Red = left, Blue = empty.)

Here supplier one has 3 products. The final prices are [3, 2, 1].

Here supplier one has 5 products. The final prices are [5, 4, 3, 2, 1]

…

The highest profit is 10 + 9 + 8 + 2*7 + 3*6 + 4*5+ 4*4 + 4*3 = 107

###### More Amazon Online Assessment Questions 2021

#### Get one-to-one training from Google Facebook engineers

##### Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.

Most recent interview questions and system design topics gathered from aonecode alumnus.

One-to-one online classes. Get feedbacks from real interviewers.

##### Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.

New to the ground? - Develop basic coding skills with your own designated mentor.

Days before interview? - Focus on most important problems in target company question bank.