Saleh127

CF 1131C

Jul 24th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. int main()
  7. {
  8. fellow_junior
  9. ll a[20000],c,d,e,f,i,j,k,l;
  10. cin>>c;
  11. for(i=0;i<c;i++)
  12. {
  13. cin>>a[i];
  14. }
  15. sort(a,a+c);
  16. ll x[c];
  17. i=0,j=c-1;
  18. l=1;
  19. for(k=0;k<c;k++)
  20. {
  21. if(i>j) break;
  22. if(l%2==1)
  23. {
  24. x[i]=a[k];
  25. i++;
  26. l++;
  27. }
  28. else if(l%2==0)
  29. {
  30. x[j]=a[k];
  31. j--;
  32. l++;
  33. }
  34. }
  35. for(k=0;k<c;k++)
  36. {
  37. cout<<x[k]<<" ";
  38. }
  39. cout<<endl;
  40. return 0;
  41. }
  42.  
Add Comment
Please, Sign In to add comment