#C12339. Merge Two Sorted Lists

    ID: 41755 Type: Default 1000ms 256MiB

Merge Two Sorted Lists

Merge Two Sorted Lists

You are given two lists of integers, each of which is sorted in ascending order. Your task is to merge these two lists into a single sorted list.

The merging process should be performed in linear time using the two-pointer technique. More formally, if the first list has length \(n\) and the second has length \(m\), you can merge them in \(O(n+m)\) time.

Please note: Input will be read from stdin and output should be written to stdout.

inputFormat

The input consists of four lines:

  1. The first line contains an integer \(n\), representing the number of elements in the first list.
  2. The second line contains \(n\) space-separated integers, representing the first sorted list.
  3. The third line contains an integer \(m\), representing the number of elements in the second list.
  4. The fourth line contains \(m\) space-separated integers, representing the second sorted list.

outputFormat

Output a single line containing the merged sorted list. The numbers should be separated by a single space.

## sample
3
1 3 5
3
2 4 6
1 2 3 4 5 6