General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
87708900 Practice:
sreyans
999D - 32 Python 3 Accepted 1154 ms 37136 KB 2020-07-22 21:28:45 2020-07-22 21:28:45
→ Source
n,m=map(int,input().split())
a=list(map(int,input().split()))
summ=sum(a)
k=[[[],0] for i in range(m)]
for i in range(n):
    k[a[i]%m][0].append(i)
    k[a[i]%m][1]+=1
#print(k)
j=0
l=n//m
for i in range(m):
    while(k[i][1]>l):
        while(j<i or k[j%m][1]>=l):
            j+=1
        z=k[i][0].pop()
        k[i][1]-=1
        a[z]+=(j-i)%m
        k[j%m][0].append(z)
        k[j%m][1]+=1
print(sum(a)-summ)
print(*a)

?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details