Fantastic Sorting Algorithm

Sort a sequence of integers in non-decreasing order by repeating a single operation: Delete any of one of the numbers in the sequence and add it to an existing number. For example, to sort (3,2,2), simply take one of the 2’s and add to other 2 to get (3,4) in a single operation. Input A number of of inputs (≤ 150), each starting with n on a line, followed by a line with n numbers ai (1≤n≤5000,1≤ai ≤100000). Output For each input, output the minimum number of operations required to sort the sequence. Sample Input 3 322 5 82731 Sample Output 1 3