General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
137991546 Practice:
brthyyjp
999D - 32 PyPy 3 Accepted 780 ms 28796 KB 2021-12-04 16:25:04 2021-12-04 16:25:04
→ Source
n,m = map(int, input().split())
A = list(map(int, input().split()))
C = [[] for i in range(m)]
k = n//m
for i, a in enumerate(A):
    C[a%m].append(i)
ans = 0
R = []
for i in range(2*m):
    r = i%m
    while len(C[r]) > k:
        j = C[r].pop()
        R.append((j, i))
    while len(C[r]) < k and R:
        j, pi = R.pop()
        C[r].append(j)
        A[j] += i-pi
        ans += i-pi
print(ans)
print(*A)
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details