Mr. Myers is preparing an exam with N questions. He has an array marks of length N, where marks[i] is the maximum mark originally assigned to the i-th question.
He wants to reassign the marks so that all of the following hold:
-
Every reassigned mark is a distinct positive integer.
-
Each reassigned mark is greater than or equal to the original value for that question.
-
The total sum of the reassigned marks is minimized.
Return the minimum possible total sum of the reassigned marks.
Function Signature
def min_total_marks(marks: list[int]) -> int:
Rules
-
marks
is not sorted, and values may repeat.
-
Return only the minimum total as an integer. The assignment itself is not returned.
-
The total can exceed the 32-bit integer range (it can reach about
10^14
).
Constraints
-
1 <= N <= 10^5
-
1 <= marks[i] <= 10^9
Examples
Input: marks = [1, 2, 2, 3]
Output: 10
In sorted order the marks become 1, 2, 3 (the second 2 is taken) and 4 (3 is now taken), so the total is 1 + 2 + 3 + 4 = 10. No answer can be lower, because four distinct positive integers always sum to at least 10.
Input: marks = [5, 5, 5, 5, 5]
Output: 35
Every mark must be at least 5 and all five must differ, so the cheapest choice is 5, 6, 7, 8 and 9, which sum to 35.
Input: marks = [3, 1, 3, 10, 2]
Output: 20
In sorted order the marks become 1, 2, 3, 4 and 10. The originals already sum to 19, and the two 3s cannot both stay at 3, so 20 is the least possible total.