fork download
  1. /*
  2. * author : lx_lovin
  3. */
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6.  
  7. int main()
  8. { ios::sync_with_stdio(0);
  9. cin.tie(0);
  10. long si;cin>>si;
  11. long x,cost=0;
  12. map<long,int> M;
  13. for(long i=0;i<si;i++){
  14. cin>>x;
  15. M[x]++;
  16. }
  17. cost = (long)(si/2) - M.size();
  18. if(cost<0)cost=0;
  19. map<long,int> Ans;
  20. for(auto x:M){
  21. Ans[x.first]++;
  22. M[x.first]--;
  23. if(Ans.size()==(int)si/2){
  24. break;
  25. }
  26. }
  27. map<long,int>::iterator it = M.begin();
  28. long k=0;
  29. while((int)Ans.size() < (int)si/2){
  30. if(Ans[k]==0){
  31. Ans[k]++;
  32. }else{
  33. k++;
  34. }
  35. }
  36. while(it!=M.end()){
  37. it++;
  38. }
  39. long temp = cost;
  40. while(temp--){
  41. if(it->second > 0){
  42. it->second--;
  43. }else{
  44. it--;
  45. }
  46. }
  47. it = M.begin();
  48. cout<<cost<<endl;
  49. for(auto x:Ans){
  50. cout<<x.first<<" ";
  51. }
  52. long hui=0;
  53. while(1){
  54. if(it->second>0){
  55. cout<<it->first<<" ";
  56. it->second--;
  57. hui++;
  58. if(hui>=(int)si/2)break;
  59. }else{
  60. it++;
  61. }
  62. }
  63. cout<<endl;
  64. return 0;
  65. }
Success #stdin #stdout 0s 4152KB
stdin
6
0 0 0 1 1 1
stdout
1
0 1 2 0 0 1