How can I partition a multiset of integers, $A$, of size $N=MK$, into $K$ equal-sized multisets, $G_1,G_2,\ldots,G_K$, such that $\sum_i \mathrm{\lvert \min(G_i)\rvert}$ is maximized? Here, $\min(G)$ denotes the multiset consisting of a single element, the minimum element of $G$, with multiplicity equal to the element's multiplicity in $G$.

Or in simple words-

Given $N$ integers, I have to group them with each group having $M$ integers in it. Now each group has to have integers with same values so to do that we can only decrease the value of integers.

Now I want to minimize the number of those transformation.

Eg - N=5 M=5
2 2 2 2 10
We can decrease 10 to 2.
Group - (2,2,2,2,2)
No. of Transformation=1

Eg 2 - N=6 M=3
1 2 4 7 1 5
We can reduce 4 to 1 ,  5  and 7 to 2 
Groups - (1,1,1) , (2,2,2)
No. of Transformations=3

I hope this example makes it a bit more clear

 Eg - 3 : N=8
    1 2 2 5 5 6 6 1
    (a) M=2
    Groups - (1,1),(2,2),(5,5),(6,6)
    without reducing any number - optimal solution
    No. of Transformation=0
    (b) M=4
    Groups - (1,1,1,1),(5,5,5,5)
    Here all 2's were reduced to 1 and all 6's to 5 - optimal solution
    No. of Transformations=4

I first thought of Hit and Trial which will be very time consuming. Then I thought of sorting the list and then pick M elements in the list and then answer will be sum of elements that are larger than the smallest element in each group. But this is not correct approach and will often give wrong answer.

Is there an optimal and efficient way to do this and find number of transformations?

  • $\begingroup$ Your question is unclear. "each group has to have integers with same values" - yet that doesn't happen in your second example, so I think you must mean something different. Are you trying to minimize $M$, or the value of the integers? What is allowed to change? What happened to the $10$ in $M$ in the first example, and why didn't it happen to any value in the second example? $\endgroup$
    – Joffan
    Commented Dec 4, 2016 at 19:58
  • $\begingroup$ @Joffan in each group every integer should be same. I corrected the typos. $10$ in first group got reduced to $2$ and same happened in 2nd example. $\endgroup$
    – Buckster
    Commented Dec 4, 2016 at 20:15
  • $\begingroup$ Thanks for the clarifications. Would $\{(1,1,1,1),(2,2,2,2)\}$, using $(5\to 1, 6\to 2)$, be regarded as a lesser solution for the additional example? Or just as good? Does every number in the original problem need to be transformed in the same way? $\endgroup$
    – Joffan
    Commented Dec 4, 2016 at 20:29
  • $\begingroup$ @Joffan I think it will be as good because in the end, the goal is to find out the least number of integers that will be transformed.In example you reffered to,in both the cases, the way I did and the way you did it, the optimal answer will be 4. $\endgroup$
    – Buckster
    Commented Dec 4, 2016 at 20:35
  • $\begingroup$ You can write your problem more concisely as this: How can I partition a multiset of integers, $A$, of size $N=MK$, into $K$ equal-sized multisets, $G_1, G_2, \ldots, G_K$, such that the size of the multiset-intersection $A \cap \{\min(G_i)\}$ is maximized? $\endgroup$
    – dshin
    Commented Dec 4, 2016 at 20:38

1 Answer 1


I would think of a somewhat greedy approach. One of your sets will include the smallest element of $A$ and clearly it should get all the copies of that element. The rest of the $M$ slots do not matter for your total score. If there are several copies of the next smallest element, they should all go in another set. If there is only one, put it in the first set so it doesn't give you a score of $1$. Look for the elements that have lots of copies and put them in a set together, then see if you can fill the set up with larger numbers. Start with the best score you can get by picking the $G_i$ of highest quantity, then see if you can fill the non-counting slots with elements higher than $G_i$. If you run into trouble, you need to choose a different set of target $G_i$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .