#P1818. Minimum Votes for Lowering Average Score

    ID: 15101 Type: Default 1000ms 256MiB

Minimum Votes for Lowering Average Score

Minimum Votes for Lowering Average Score

You are given a movie rating system where each vote must be an integer between 1 and 10 (inclusive). The movie already has some votes, and you want to cast as few additional votes as possible (each vote being the minimum score of 1) so that the overall average rating becomes strictly less than a given threshold x.

Formally, you are given an integer n and a number x. There are n existing votes with ratings a1, a2, ..., an. You are allowed to add additional votes, each having a rating of 1. Let the sum of the existing votes be S = a1 + a2 + ... + an. After adding k votes, the new average rating becomes
\[ \frac{S+k}{n+k}

Your task is to find the minimum non-negative integer k required so that the overall average falls strictly below x. If x is less than or equal to 1 then it is impossible to lower the average below x since each vote is at least 1; in that case, output -1.

inputFormat

The input consists of two lines:

  1. The first line contains two numbers: an integer n (the number of existing votes) and a number x (the target threshold for the average).
  2. The second line contains n space-separated integers representing the current movie ratings (each between 1 and 10).

outputFormat

Output a single integer: the minimum number of additional votes (each with the value 1) needed so that the new average rating is strictly less than x. If it is not possible, output -1.

sample

3 4
5 5 5
2