This page is still under construction.

Parts of this page are still being built. What you see may change.

Renovation

Time limit1sMemory limit1024 MB

Summary
Assign each needed nail to a longer or equal existing nail, or buy a new one, minimizing the number bought and then their total length.
Level

Medium5 of 10

Topics
Greedy, Sorting, Two pointers, Brute force
Solved
No attempts yet

Problem

Johanna is renovating her apartment. Because Johanna does not like leaving things to chance, she has planned in detail exactly how many nails she needs for the renovation. In total she needs NN nails with lengths x1,x2,…,xNx_1, x_2, \dots, x_N. In her nail box she has MM nails with lengths y1,y2,…,yMy_1, y_2, \dots, y_M.

If Johanna needs a nail of length xix_i, she can use a nail of length yjy_j if xi≤yjx_i \le y_j, because she can cut the longer nail down until it is exactly as long as needed. She cannot, however, combine two short nails into a longer nail, or cut a nail more than once, since it has only one nail head.

Before Johanna starts the renovation, she wants to know:

  • how many nails she needs to buy, and
  • what lengths the nails she needs to buy should have.

She wants to buy as few nails as possible, and in addition wants to buy nails of as short a total length as possible.

Input

The first line contains two integers 1≤N≤151 \le N \le 15 and 1≤M≤151 \le M \le 15, the number of nails Johanna needs and the number of nails Johanna has. The second line contains NN integers 1≤x1,x2,…,xN≤1001 \le x_1, x_2, \dots, x_N \le 100, the lengths of the nails Johanna needs. The third line contains MM integers 1≤y1,y2,…,yM≤1001 \le y_1, y_2, \dots, y_M \le 100, the lengths of the nails Johanna has.

Output

The program should first print one integer: the minimum number of nails Johanna needs to buy. On the next line, the program should print the lengths of the nails Johanna should buy, in ascending order.

Hint

In example 1, Johanna only needs to add three extra nails of lengths 1313, 2828, and 7777.

In example 2, Johanna needs to buy one more nail of length 1111, and also cut a nail of length 100100 down to 5050. She could have bought a nail of length 5050 and cut the nail of length 100100 down to length 1111, but then she would need to buy nails of a longer total length.

Examples2

  1. Example 1

    Input
    6 3
    64 13 45 28 82 77
    45 82 64
    
    Expected output
    3
    13 28 77
    
  2. Example 2

    Input
    3 2
    11 50 45
    45 100
    
    Expected output
    1
    11