Adjusted Average
Time limit8sMemory limit1024 MB
Given n samples, remove at most k of them so the remaining average is as close as possible to a target value, and output the minimal absolute difference.
- Level
Medium6 of 10
- Topics
- Sorting, Two pointers, Math
- Solved
- No attempts yet
Input
As a student of the Biology And Probability Course at your university, you have just performed an experiment as part of the practical assignments. However, your results do not look very nice: you had hoped that the average of your samples would be different from what it is now.
To improve your results, you decide to let some of your samples "magically disappear" (i.e., dump them in the waste bin). In order to not raise suspicion with your teacher, you can remove only a few of your samples. How close can you possibly get to your desired average?
Output
The input consists of:
- One line with three integers , , and (, , , ), the number of samples, the number of samples that may be removed, and the average you think looks the nicest.
- One line with integers (), representing the samples.
Output
Output the minimal absolute difference between and the average you can obtain by removing at most samples from the dataset.
Your answer should have an absolute error of at most .