Official

B - Grapes Editorial by en_translator Editorial for printing


Solution 1

It is sufficient to naively simulate the procedure in the problem statement.

Sample code (Python)

N, M = map(int, input().split())
ans = [0] * N
x = 0
for _ in range(M):
  ans[x] += 1
  x += 1
  if x == N:
    x = 0
for a in ans:
  print(a)

Solution 2

One can directly calculate the number of grapes person \(i\) receives.

For example, let \(q\) and \(r\) be the quotient and remainder when \(M\) is divided by \(N\). Then the number of grapes person \(i\) receives is \((q+1)\) if \(1\leq i\leq r\), and \(q\) if \(r\lt i \leq N\). Therefore, printing \((q+1)\) over \(r\) lines and \(q\) over \((N-r)\) lines will be accepted.

Sample code (Python)

N, M = map(int, input().split())
q, r = M // N, M % N
for _ in range(r):
  print(q + 1)
for _ in range(N - r):
  print(q)

posted:
last update: