№ |
Отправитель |
Задача |
Язык |
Вердикт |
Время |
Память |
Отослано |
Протест. |
|
44042993 |
Дорешивание:
Chloris |
999D
- 32
|
C++17 (GCC 7-32)
|
Полное решение
|
545 мс
|
8016 КБ
|
2018-10-09 18:42:38 |
2018-10-09 18:42:38 |
|
#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]<<" ";
}
Время: ? ms, память: ? КБ