1743: Marble Top

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

We install marble countertops. The marble comes in a standard width but varying lengths. It is very difficult to cut the marble -- we have a special machine that cuts a length of marble into two pieces, one of which must be exactly k feet long. A piece that is no bigger than k cannot be cut. int[] stock contains the lengths of marble that we have on hand, and int[] orders contains the lengths that our customers have ordered. Given k, stock, and orders, return the minimum number of cuts needed to satisfy all our customers. If it is not possible, return -1.

输入

Line 1:k will be between 1 and 40, inclusive. Line 2:the number of stock(1~50) Line 3:the specified number of each element in the int[] stock between 1 and 40.There should be a space between each two elements. Line 4:the number of order(1~50) Line 5: the specified number of each element in the int[] order between 1 and 40.There should be a space between each two elements.

输出

Return the minimum number of cuts needed to satisfy all customers. If it is not possible, return -1.

样例输入 复制

5
3
5 3 11
3
10 3 5
1
4
7 6 2 1
7
3 1 1 1 1 1 1

样例输出 复制

-1
4

来源/分类