Editorial for Rating


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
Analiz ve Çözüm Yolu

Puanlamaların toplamını bulmak için ortalama değer ile veri sayısının çarpımını alabiliriz: \(Mean \cdot N\). Ayrıca puanlamaların toplamının bir maksimum değer ile kalan tüm değerlerin minimum olduğu durumdan büyük ya da bu duruma eşit olması gerektiğini de görebiliyoruz: \(Min \cdot (N - 1) + Max\). Bunun tam tersi olarak bir minimum değer ile kalan tüm değerlerinin maksimum olduğu durumda da eşitlik ya da küçüklük söz konusu olmak zorunda: \(Max \cdot (N - 1) + Min\). Böylece aşağıdaki koşul sağlandığı sürece bir çözüm bulabiliriz:

\( Min \cdot (N - 1) + Max ≤ Mean \cdot N ≤ Max \cdot (N - 1) + Min \)

Eğer geçerli bir çözüm varsa, ona birden fazla yolla ulaşılabilir. Örneğin, sonuncusu hariç tüm puanlamaları \(Min\) yapalım, sonuncuyu da \(Max\). Sonra da puanlamalar toplamı \(Mean \cdot N\) 'den küçük olduğu sürece \(Max\)'dan küçük herhangi bir puanı seçip 1 arttıralım.

Analysis and Guide for Solution

It's easy to see that the sum of ratings should be equal to \(Mean \cdot N\). On the other hand the sum of ratings is not less than \(Min \cdot (N - 1) + Max\). and it is not greater than \(Max \cdot (N - 1) + Min\). Thus a solution exists as long as:

\( Min \cdot (N - 1) + Max ≤ Mean \cdot N ≤ Max \cdot (N - 1) + Min \)

There are multiple possible ways to build a valid solution if there is any. For example, let's assign all ratings to \(Min\) except of the last one which will be equal to \(Max\). Then while rating sum is less then \(Mean \cdot N\) choose any rating smaller than \(Max\) and increment it by one.