Rectangle Tiling
문제
Consider a rectangle with integer side lengths. A square tiling of the rectangle is a covering of the entire region using non-overlapping squares whose sides are parallel with those of the rectangle. In a square tiling, no square may overhang (extend beyond the rectangle's boundary).
You have a collection of squares with side lengths being powers of . Find a square tiling of the rectangle using the fewest squares possible, or, indicate that it cannot be done.
Figure 1: Optimal square tilings for the first three sample inputs. The small unlabelled tiles are tiles.
입력
The first line of input contains three integers and ( and ). Here, and indicate the dimensions of the rectangle. The next line contains integers where () is the number of squares you own.
출력
If there is a square tiling of a rectangle using the squares you own, output the minimum number of squares needed in such a square tiling. Otherwise, output if there is no square tiling of the rectangle using the squares you own.
예제
예제 1
4 2 2 5 1
5
예제 2
6 7 3 10 10 10
12
예제 3
17 20 5 20 0 4 0 1
25
예제 4
4 2 3 3 1 10
-1