알고리즘 문제풀이

멀티탭 스케줄링 [백준 1700]

wiojfe 2025. 3. 8. 19:02

https://www.acmicpc.net/problem/1700

 

# 입력 받기
n, k = map(int, input().split())  # n: 멀티탭 구멍 수, k: 사용 순서 길이
order = list(map(int, input().split()))
multitap = []
swap_count = 0

for i in range(k ):
    curr = order[i] 


for i in range(k):
    current = order[i]
    if current in multitap:        continue
    if len(multitap) < n:
        multitap.append(current)
        continue
    farthest = -1
    index_to_remove = -1
    for j in range(n):
        try:
            next_use = order[i+1:].index(multitap[j])
        except ValueError:
            index_to_remove = j
            break
        if next_use > farthest:
            farthest = next_use
            index_to_remove = j
    multitap[index_to_remove] = current
    swap_count += 1

print(swap_count)