305259: CF999D. Equalize the Remainders

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:28 Solved:0

Description

Equalize the Remainders

题目描述

You are given an array consisting of $ n $ integers $ a_1, a_2, \dots, a_n $ , and a positive integer $ m $ . It is guaranteed that $ m $ is a divisor of $ n $ . In a single move, you can choose any position $ i $ between $ 1 $ and $ n $ and increase $ a_i $ by $ 1 $ . Let's calculate $ c_r $ ( $ 0 \le r \le m-1) $ — the number of elements having remainder $ r $ when divided by $ m $ . In other words, for each remainder, let's find the number of corresponding elements in $ a $ with that remainder. Your task is to change the array in such a way that $ c_0 = c_1 = \dots = c_{m-1} = \frac{n}{m} $ . Find the minimum number of moves to satisfy the above requirement.

输入输出格式

输入格式


The first line of input contains two integers $ n $ and $ m $ ( $ 1 \le n \le 2 \cdot 10^5, 1 \le m \le n $ ). It is guaranteed that $ m $ is a divisor of $ n $ . The second line of input contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 0 \le a_i \le 10^9 $ ), the elements of the array.

输出格式


In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from $ 0 $ to $ m - 1 $ , the number of elements of the array having this remainder equals $ \frac{n}{m} $ . In the second line, print any array satisfying the condition and can be obtained from the given array with the minimum number of moves. The values of the elements of the resulting array must not exceed $ 10^{18} $ .

输入输出样例

输入样例 #1

6 3
3 2 0 6 10 12

输出样例 #1

3
3 2 0 7 10 14 

输入样例 #2

4 2
0 1 2 3

输出样例 #2

0
0 1 2 3 

Input

暂时还没有翻译

Sample Input Copy


Sample Output Copy


HINT

给定n和m,请问和n个数模m的余数分别是多少?现在可以执行的操作是:让其中一个数增加1,请问至少操作多少次,每一种余数的数量都相等?输出最终每个数字分别加到多少?

加入题单

上一题 下一题 算法标签: