AmazonOA #68
Can All Packages Be Delivered
估计中等可在线判题
Each time, deliver one package with any truck whose current capacity is sufficient; that truck's capacity then becomes its current capacity divided by 2, rounded down. Packages may be delivered in any order; determine whether all of them can be delivered. Each test case on this site gives one independent scenario, corresponding to a single scenario among the source's multiple scenarios.
输入格式
The first line contains n m (both 1..100000), the second line contains n capacities, and the third line contains m weights, all 1..10⁹.
输出格式
Output a single integer answer.
样例 1
输入:
1 4
8
8 4 2 1
输出:
1
样例 2
输入:
1 2
3
2 2
输出:
0
样例 3
输入:
2 2
4 3
3 4
输出:
1
样例说明
Example 1: the only truck's capacity goes 8, 4, 2, 1, exactly enough to deliver everything, so output 1. Example 2: after delivering 2 the capacity is only 1, so the second 2 cannot be delivered; output 0. Example 3: capacity 4 delivers weight 4 and capacity 3 delivers weight 3; output 1.