Monk And Champions League
Practice
4 (95 votes)
Approved
Easy
Heaps
Open
Priority queue
Problem
79% Success 11084 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Monk's favourite game is Football and his favourite club is "Manchester United". Manchester United has qualified for the Champions League Final which is to be held at the Wembley Stadium in London. So, he decided to go there and watch his favourite team play. After reaching the stadium, he saw that many people have lined up for the match tickets. He knows that there are M rows in the stadium with different seating capacities. They may or may not be equal. The price of the ticket depends on the row. If the row has K(always greater than 0) vacant seats, then the price of the ticket will be K pounds(units of British Currency). Now, every football fan standing in the line will get a ticket one by one.
Given the seating capacities of different rows, find the maximum possible pounds that the club will gain with the help of the ticket sales.

Input:
The first line consists of M and N. M denotes the number of seating rows in the stadium and N denotes the number of football fans waiting in the line to get a ticket for the match.
Next line consists of M space separated integers X[1],X[2],X[3].... X[M] where X[i] denotes the number of empty seats initially in the ith row.

Output:
Print in a single line the maximum pounds the club will gain.

Constraints:
1 <= M <= 1000000
1 <= N <= 1000000
1 <= X[i] <= 1000000
Sum of X[i] for all 1 <= i <= M will always be greater than N.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
9 votes
Tags:
Data StructuresPriority queueTrees
Points:20
25 votes
Tags:
Data StructuresEasyHash MapsHash TablesHeapsPriority queueTrees
Points:20
20 votes
Tags:
Ad-HocData StructuresEasyHeapsTrees