정리정돈

[백준 11728] 배열 합치기(Python) 본문

알고리즘/백준

[백준 11728] 배열 합치기(Python)

XZXXZX 2022. 3. 24. 14:46
728x90
반응형

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

 

11728번: 배열 합치기

첫째 줄에 배열 A의 크기 N, 배열 B의 크기 M이 주어진다. (1 ≤ N, M ≤ 1,000,000) 둘째 줄에는 배열 A의 내용이, 셋째 줄에는 배열 B의 내용이 주어진다. 배열에 들어있는 수는 절댓값이 109보다 작거

www.acmicpc.net

 

n, m = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
answer = []
a_start = 0
b_start = 0
while a_start < n or b_start<m:
  if b_start >= m or (a_start < n and a[a_start] <= b[b_start]):
    answer.append(a[a_start])
    a_start += 1
  else:
    answer.append(b[b_start])
    b_start += 1
print(' '.join(list(map(str,answer))))

알고리즘 분류

  • 정렬
  • 투 포인터
728x90
반응형