Advertisement
Void-voiD

Untitled

Mar 6th, 2023
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | Source Code | 0 0
  1. n = int(input())
  2. a = list(map(int, input().split()))
  3.  
  4. to_sort = a[::2]
  5. not_sort = a[1::2]
  6.  
  7. to_sort.sort()
  8.  
  9. a = [0] * n
  10. for i in range(n // 2):
  11.     a[i * 2] = to_sort[i]
  12.     a[i * 2 + 1] = not_sort[i]
  13. if n % 2 == 1:
  14.     a[-1] = to_sort[-1]
  15.  
  16. print(*a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement