#K37297. Minimum Additional Score Needed for Passing Average
Minimum Additional Score Needed for Passing Average
Minimum Additional Score Needed for Passing Average
In many academic settings, a student might need to take an extra exam to achieve a required passing average for the class. Given the current scores of the class and a required average, determine the minimum score that the new exam must have to reach the desired overall average.
Formally, if there are \(N\) students with scores \(a_1, a_2, \ldots, a_N\) and the required overall average after including one additional score is \(R\), you need to find the smallest integer \(S\) such that:
\[ \frac{a_1 + a_2 + \cdots + a_N + S}{N+1} \ge R \]
If the computed additional score is not positive, output 0.
inputFormat
The input begins with an integer (T) denoting the number of test cases. For each test case, the first line contains an integer (N) representing the number of students. The second line contains (N) space-separated integers representing the scores of the students. The third line contains an integer (R), the required average.
outputFormat
For each test case, output a single integer on a new line: the minimum required score on the additional exam.## sample
3
4
10 20 30 40
25
3
50 60 70
60
5
65 70 75 80 85
75
25
60
75
</p>