atcoder#KEYENCE2021B. Mex Boxes
Mex Boxes
Score : points
Problem Statement
Snuke has balls, each with an integer written on it. The numbers on the balls are .
He has decided to put these balls in boxes. Every ball must be in some box, but there may be boxes with zero or multiple balls.
After he put the balls in the boxes, the lid of each box will show an integer. Let be the integer shown on a box. is the minimum non-negative integer such that the box contains no ball with . For example, the lid of an empty box will show ; the lid of a box with balls will show ; the lid of a box with balls will show .
Find the maximum possible sum of the integers the lids show.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible sum of the integers the lids show.
4 2
0 1 0 2
4
- An optimal solution is to allocate the sets of balls to the boxes.
- In this case, the lids show , respectively, for a total of .
5 2
0 1 1 2 3
4
- An optimal solution is to allocate the (multi)sets of balls to the boxes.
- In this case, the lids show , respectively, for a total of .
- Note that we may have empty boxes.
20 4
6 2 6 8 4 5 5 8 4 1 7 8 0 3 6 1 1 8 3 0
11