?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
214236980 |
Practice: mazeneldeeb |
999D - 32 | C++14 (GCC 6-32) | Accepted | 530 ms | 9568 KB | 2023-07-17 19:25:20 | 2023-07-17 19:25:20 |
#include<bits/stdc++.h> using namespace std; set<long long int>s; int main() { long long int n,m,i,ans=0; cin>>n>>m; long long int a[n],c[200005]={0}; for(i=0;i<m;i++)s.insert(i); for(i=0;i<n;i++) { long long int d,x; cin>>a[i]; d=a[i]%m; if(d>*s.rbegin())x=*s.begin(); else x=*s.lower_bound(d); if(++c[x]==n/m)s.erase(x); ans+=(x-d+m)%m; a[i]+=(x-d+m)%m; } cout<<ans<<endl; for(i=0;i<n;i++)cout<<a[i]<<" "; }
?
?
?
?