CF999D.Equalize the Remainders
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array consisting of n integers a1,a2,…,an, 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 ai by 1.
Let's calculate cr (0≤r≤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 c0=c1=⋯=cm−1=mn.
Find the minimum number of moves to satisfy the above requirement.
给你一个由 n 个整数 a1,a2,…,an 组成的数组,以及一个正整数 m。保证 m 是 n 的约数。
在一次操作中,你可以任选一个位置 i(1≤i≤n),并将 ai 增加 1。
定义 cr(0≤r≤m−1)为数组中模 m 余 r 的元素个数。换言之,对每个余数 r,统计数组 a 中模 m 余 r 的元素个数。
你的任务是通过若干次操作,使得 c0=c1=⋯=cm−1=mn。
求满足上述条件所需的最少操作次数。
输入格式
The first line of input contains two integers n and m (1≤n≤2⋅105,1≤m≤n). It is guaranteed that m is a divisor of n.
The second line of input contains n integers a1,a2,…,an (0≤ai≤109), the elements of the array.
输入的第一行包含两个整数 n 和 m(1≤n≤2⋅105,1≤m≤n)。保证 m 是 n 的约数。
输入的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤109),表示数组的元素。
输出格式
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 mn.
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 1018.
第一行输出一个整数——满足以下条件所需的最少操作次数:对于每个从 0 到 m−1 的余数,数组中模 m 余该值的元素个数均等于 mn。
第二行输出任意一个满足上述条件的数组,该数组可通过最少次数的操作由给定数组得到。结果数组中各元素的值不得超过 1018。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?