AmazonOA #68
Can All Packages Be Delivered
Estimated MediumJudge-ready
Topics (AI-labelled)Stacks & HeapsGreedy
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.
Input
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
Output a single integer answer.
Example 1
Input:
1 4
8
8 4 2 1
Output:
1
Example 2
Input:
1 2
3
2 2
Output:
0
Example 3
Input:
2 2
4 3
3 4
Output:
1
Example notes
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.
Editorial
Loading solution…