##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You are given two arrays and .
For a subset , define its score as:
Here, of a multiset of integers is the smallest non-negative integer that does not appear in it.
Now Meximus Minimus Decimus Meridius, Prime Minister of Repovive land, wants to partition set into exactly none-empty subsets such that sum of scores of these subsets is minimized. Find this minimum value.
All indices must be placed in one subset. The MEX of the values is , and the sum of the corresponding values is , so the score is .
One optimal partition is and . The first subset has score , and the second subset has MEX , so its score is .
There is no index with . Therefore, both subsets can have MEX , and the total score is .
Every index has . No matter how the indices are partitioned, each subset has MEX , so the total score is .
All indices must be placed in one subset. The MEX of the values is , and the sum of the corresponding values is , so the score is .