정올/beginner

정올 1814 자료처리 - 삽입정렬 횟수 세기

juwanseo 2025. 1. 13. 12:48

문제

 

예제

def sum(arr):
    move_count = 0
   
    for i in range(1, len(arr)):
        key = arr[i]
        j = i - 1
       
        while j >= 0 and arr[j] > key:
            arr[j + 1] = arr[j]
            move_count += 1
            j -= 1
       
        arr[j + 1] = key
    return move_count

n = int(input())
arr = list(map(int, input().split()))

move_count = sum(arr)


print(move_count)