We are given array A[], that consists of N integers. We need to count the number of subsets of A[], whose arithmetical mean is maximal. Arithmetical mean of an empty subset is undefined.
Explanation:
Let’s define MAX-VALUE as the maximal number of A[].
The answer is two to the power NUM-MAX-VALUE minus one, where NUM-MAX-VALUE is the number of times MAX-VALUE appears in A[].
Let’s have a look why the previous statement is correct.
Arithmetic mean of a set of numbers is smaller than or equal to the maximal number. Then, any subset of A[], that contains only numbers that are equal to MAX-VALUE, is suitable and gives the maximal arithmetical mean, which equals to MAX-VALUE.
At the same time, if there is one number chosen, that is smaller than MAX-VALUE, then the arithmetical mean would be smaller than MAX-VALUE.
That’s why the answer is 2^NUM-MAX-VALUE - 1.
Why we should subtract 1? Because one of the subsets, that we have counted, is empty. We mustn’t consider it as a subset, that gives the the maximal arithmetical mean.
You use function pow() from math.h library. For this problem, it is unacceptable. You should either write your own function pow(), which can process all calculations modulo 100000007, or just use a loop for counting the answer.
@xellos0 I agree with your point that c has no iostream library but c++ has math.h library, check this link in C++11, C++ maintains backword compatibility for its library.
Because the number of different subsets of an N-element set is 2 to the N’th. The logic is that each element you can either include to the current subset or not include.
@insaynasasin, the point is that in the current problem you are asked to do all the calculation modulo 10^9 + 7. As far as 32-bit integers cannot fit 2^100000 itself, we can’t just calculate 2^100000 by a loop and then find the reminder of dividing by 10^9 + 7. We need to go smarter. I.e. each time you twice your answer, make it modulo 1000000007.
I think the question was not explained properly…nor the test cases were enough for better understanding of the question…the statement of question clearly mentioned that we have to delete some(not all) elements of the array such that arithmetic mean of the REMAINING elements are as big as possible…instead it should be “we have to delete some (or none) elements of the array such that the arithmetic mean of the DELETED elements are as big as possible”…due to the statement not mentioned properly, I submitted 4 wrong solutions…finally submission was successful when I read the comments and modified my answer.
I’m not sure what do you mean, but I would say, and correct me if I’m wrong, that the statement was highly understandable.
There was no long legend, just a mathematical description of the problem. “Sereja wants to delete some(possible none, but not all) elements from the array, such that arithmetical mean of all remaining numbers will as big as possible.” It doesn’t seem clear for you? Why?
If you aren’t satisfied with this editorial, then, please, can you describe what exactly you don’t like? Maybe you would suggest some improvements?
The question said “Keeping the arithmetic mean maximal”, does that mean that the mean of the remaing elements should be equal to or greater than the mean of the original set? (sorry for noobish question again. I’m very new to all this …)