General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
117128455 Practice:
vjudge1
999D - 32 PyPy 3 Accepted 717 ms 39972 KB 2021-05-24 04:19:39 2021-05-24 04:19:39
→ Source
n, m = map(int, input().split())
k = n // m
a = list(map(int, input().split()))
cc = [[] for i in range(m)]
for i in range(n):
    cc[a[i] % m].append(i)
f = []
s = 0
for t in range(2):
    for i in range(m):
        while len(cc[i]) > k:
            f.append(cc[i].pop())
        while len(cc[i]) < k and len(f) > 0:
            p = f.pop()
            cc[i].append(p)
            d = (i - a[p]) % m
            a[p] += d
            s += d
print(s)
print(" ".join(map(str, a)))

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