You have an array A containing N elements. Suppose you select M elements from the array , then the current beauty of the array will be sum of those M elements. Every second, the beauty of the array increases by the value M. what is the minimum amount of time, the beauty of array equals the value X. N <= 100, A[i] <= 1e5 and X <= 1e9. How do i approach this problem?









The problem is to realize that to get the time down, your starting sum needs to be as big as possible.
So, start by sorting the array from largest to smallest. Then, just loop through every possible group size, from one number up to all of them. For each group size m, sum the top m numbers. See if your target value X is bigger than that sum. If it is, check if the difference can be divided evenly by m.