#K37142. Candy Distribution Minimizing Difference

    ID: 25911 Type: Default 1000ms 256MiB

Candy Distribution Minimizing Difference

Candy Distribution Minimizing Difference

You are given two integers (n) and (k), where (n) represents the number of candies and (k) represents the number of children. Your task is to distribute the candies among the children so that the difference between the number of candies any two children receive is minimized.

Each child should receive (\lfloor \frac{n}{k} \rfloor) candies as a base amount. The remaining (n \bmod k) candies should be distributed by giving one extra candy to each of the first (n \bmod k) children.

For example, if (n = 7) and (k = 3), then each child gets (\lfloor 7/3 \rfloor = 2) candies, and one candy is left over. Hence, one child gets an extra candy resulting in the distribution: [3, 2, 2].

The input will be read from standard input (stdin) as two space-separated integers and the result should be printed to standard output (stdout) as a space-separated list of integers.

inputFormat

The input consists of a single line containing two integers (n) and (k) separated by a space, where (n) is the total number of candies and (k) is the number of children.

outputFormat

Output a single line containing (k) integers separated by a space. The first (n \bmod k) numbers should be (\lfloor n/k \rfloor + 1) and the remaining should be (\lfloor n/k \rfloor).## sample

7 3
3 2 2