General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
44042993 Practice:
Chloris
999D - 32 C++17 (GCC 7-32) Accepted 545 ms 8016 KB 2018-10-09 18:42:38 2018-10-09 18:42:38
→ Source
#include <bits/stdc++.h>

using namespace std;

const int N=2e5+5;
set<int> s;
int a[N],c[N];
int main(){
	int n,m,t,p;
	long long ans=0;
	cin>>n>>m;
	int r=n/m;
	for(int i=0;i<m;i++) s.insert(i);
	for(int i=0;i<n;i++){
		cin>>a[i];
		t=a[i]%m;
		p=*s.lower_bound(t);
		if(s.lower_bound(t)==s.end()) p=*s.begin();
		a[i]+=(p-t+m)%m;
		ans+=(p-t+m)%m;
		if(++c[p]==r) s.erase(p);
	}
	cout<<ans<<endl;
	for(int i=0;i<n;i++) cout<<a[i]<<" ";
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details