#K85787. Calculate Product Discount Based on Ratings
Calculate Product Discount Based on Ratings
Calculate Product Discount Based on Ratings
Given the number of ratings, the product price, and a series of customer ratings, your task is to calculate the discount applied after each new rating is submitted. The discount is determined by the current average rating (after including the new rating) using the following rules:
- If the current average rating \(\geq 4.5\), the discount is \(20\%\) of the product price.
- If the current average rating is between \(4.0\) (inclusive) and \(4.5\) (exclusive), the discount is \(10\%\) of the product price.
- If the current average rating is between \(3.5\) (inclusive) and \(4.0\) (exclusive), the discount is \(5\%\) of the product price.
- If the current average rating is below \(3.5\), no discount is applied.
After processing each rating, output the discount (rounded down to an integer) on a new line.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains two space-separated integers \(N\) and \(P\) — where \(N\) is the number of ratings and \(P\) is the price of the product.
- The second line contains \(N\) space-separated integers representing the customer ratings.
outputFormat
For each rating update, print the discount value (as an integer) on a separate line to standard output (stdout).
## sample5 100
5 4 3 5 2
20
20
10
10
5
</p>