AmazonOA #369
Compute Maximum Earning Points
Estimated MediumJudge-ready
Topics (AI-labelled)Greedy
Each item can be bought at most once. Buying an item earns its current points, after which the points of every other unbought item decrease by 1, but not below 0. You may choose any purchase order and any number of purchases. Find the maximum total points.
Input
The first line contains n and the second line contains n initial point values. The original bounds are 1≤n≤100000, 0≤deals[i]≤1000000.
Output
Output a single integer, the answer.
Example 1
Input:
5
5 2 2 3 1
Output:
7
Example 2
Input:
3
5 5 5
Output:
12
Example 3
Input:
3
0 1 0
Output:
1
Example notes
The outputs of the three public examples are 7; 12; and 1, checked by independent enumeration or direct simulation.
Editorial
Loading solution…