█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 7085

Problema 0xde - Ordenar un arreglo grande

Caso # Resultado Tiempo Memoria
#1
Correcto
0.015 s 3 KBi
#2
Correcto
0.018 s 3 KBi
#3
Correcto
0.015 s 3 KBi
#4
Correcto
0.015 s 3 KBi
#5
Correcto
0.015 s 3 KBi
#6
Correcto
0.016 s 3 KBi
#7
Correcto
0.754 s 5 KBi
#8
Correcto
0.805 s 7 KBi
#9
Correcto
0.83 s 5 KBi
#10
Correcto
0.853 s 9 KBi
#11
Correcto
0.808 s 14 KBi
#12
Correcto
0.765 s 14 KBi
#13
Correcto
0.798 s 14 KBi
#14
Correcto
0.777 s 14 KBi
#15
Correcto
0.82 s 14 KBi
#16
Correcto
0.868 s 14 KBi
#17
Correcto
0.879 s 14 KBi
#18
Correcto
0.761 s 15 KBi
#19
Correcto
0.764 s 14 KBi
#20
Correcto
0.826 s 5 KBi
#21
Correcto
0.765 s 14 KBi
#22
Correcto
0.783 s 14 KBi
#23
Correcto
0.772 s 14 KBi
#24
Correcto
0.806 s 15 KBi
#25
Correcto
0.793 s 15 KBi
#26
Correcto
0.816 s 14 KBi
#27
Correcto
0.792 s 14 KBi
Puntos totales: 100 / 100

Código

def merge(arr, l, m, r):
    n1 = m - l + 1
    n2 = r - m

    L = [0] * (n1)
    R = [0] * (n2)

    for i in range(0, n1):
        L[i] = arr[l + i]
 
    for j in range(0, n2):
        R[j] = arr[m + 1 + j]
 
    i = 0    
    j = 0   
    k = l     
 
    while i < n1 and j < n2:
        if L[i] <= R[j]:
            arr[k] = L[i]
            i += 1
        else:
            arr[k] = R[j]
            j += 1
        k += 1

    while i < n1:
        arr[k] = L[i]
        i += 1
        k += 1

    while j < n2:
        arr[k] = R[j]
        j += 1
        k += 1
 
def mergeSort(arr, l, r):
    if l < r:
        m = l+(r-l)//2
 
        mergeSort(arr, l, m)
        mergeSort(arr, m+1, r)
        merge(arr, l, m, r)
 

n = int(input())
arr = [int(item) for item in input().split()]
 
mergeSort(arr, 0, n-1)

for i in arr:
    print(i, end=" ")