#P11371. Equal Candy Distribution

    ID: 13448 Type: Default 1000ms 256MiB

Equal Candy Distribution

Equal Candy Distribution

In a kindergarten, there are n children. The i-th child initially has ai candies. The teacher can perform an unlimited number of operations. In each operation, she selects one child and gives that child k candies.

The teacher's goal is to make the number of candies equal for all children in order to avoid conflicts. To achieve this, the final number of candies each child gets must be at least as large as the maximum initial candy count, and since candies can only be added in multiples of k, the differences between the final count and the initial counts must be divisible by k.

Formally, let \(m = \max_{1\leq i\leq n} a_i\). Then for every \(i\), the difference \(m - a_i\) must be divisible by \(k\) (i.e. \(a_i \equiv m \pmod{k}\)). If this condition is satisfied, the teacher can achieve the goal by performing \(\sum_{i=1}^{n} \frac{m-a_i}{k}\) operations. Otherwise, it is impossible to equalize the candies.

Output YES and the minimum number of operations if the goal can be achieved, otherwise output NO.

inputFormat

The first line contains two integers n and k — the number of children and the number of candies given in each operation.

The second line contains n integers \(a_1, a_2, \ldots, a_n\) where \(a_i\) is the number of candies the i-th child initially has.

outputFormat

If it is possible to equalize the number of candies, print YES on the first line and the minimum number of operations on the second line. Otherwise, print NO.

sample

3 2
2 4 6
YES

3

</p>