Saleh127

CF 1419D2

Sep 20th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);
  9. cout.tie(0);
  10.  
  11. vector<ll>a,c,d,e;
  12. ll n,f,i,j,k,l=0;
  13. cin>>n;
  14. for(i=0; i<n; i++)
  15. {
  16. cin>>j;
  17. a.push_back(j);
  18. }
  19. sort(a.begin(),a.end());
  20.  
  21. f=n/2;
  22. for(i=0; i<f; i++)
  23. {
  24. c.push_back(a[i]);
  25. }
  26. for(i=f; i<n; i++)
  27. {
  28. d.push_back(a[i]);
  29. }
  30.  
  31. if(n%2)
  32. {
  33. for(i=0; i<f; i++)
  34. {
  35. e.push_back(d[i]);
  36. e.push_back(c[i]);
  37. }
  38. e.push_back(d[i]);
  39. }
  40. else
  41. {
  42. for(i=0; i<f; i++)
  43. {
  44. e.push_back(d[i]);
  45. e.push_back(c[i]);
  46. }
  47. }
  48. for(i=0;i<n-1;i++)
  49. {
  50. if(e[i]<e[i-1] && e[i]<e[i+1])
  51. {
  52. l++;
  53. }
  54. }
  55. cout<<l<<endl;
  56. for(i=0;i<n;i++)
  57. {
  58. cout<<e[i]<<" ";
  59. }
  60.  
  61.  
  62. return 0;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment