You have two non-decreasing sorted lists of n and m elements Your task is to merge them into one sorted list of size n + m Input The program receives as input two numbers n and m - the number of elements of the first list and the second list Then the elements of the first sorted list come from a new line, and from the next line - the second list Output Merge two lists into one in non-decreasing order and output the elements of the resulting list P.S: it is forbidden to use the built-in sorting Note: to display the resulting list, you can use the following construction print(*result) # where result is the final list
n = int(input()) m = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [] i = 0 j = 0 while i < n or j < m: if i < n and j < m: if a[i] < b[j]: c.append(a[i]) i += 1 else: c.append(b[j]) j += 1 elif i < n: c.append(a[i]) i += 1 elif j < m: c.append(b[j]) j += 1 print(*c)