AmazonOA #379
Get Trucks for Items
Estimated MediumJudge-ready
Topics (AI-labelled)Binary SearchIn-place Arrays
Each package independently chooses a truck whose capacity is strictly greater than its weight: first minimize the capacity, then choose the smallest original index among trucks with that capacity. Indices start at 0; output −1 if no truck is available. Loading does not consume truck capacity.
Input
The first line contains n m, the second line contains n capacities, and the third line contains m weights. Original bounds: 1≤n,m≤100000; capacities and weights are all 1..10^9.
Output
Output m truck indices or −1, in package order.
Example 1
Input:
4 3
5 3 5 8
3 5 8
Output:
0 3 -1
Example 2
Input:
2 3
4 2
1 2 4
Output:
1 0 -1
Example 3
Input:
3 2
2 2 3
1 2
Output:
0 2
Example notes
The outputs of the three public examples are, in order: 0 3 -1; 1 0 -1; 0 2. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…