i holds batches[i] items. There is also a list of packing options pack_sizes: option j packs goods into boxes of exactly pack_sizes[j] items each.
A batch can be packed with option j only if its size is divisible by pack_sizes[j], with no partly filled box left over. For every batch, pick the fitting option with the smallest index. If no option fits, write -1.
Return an array whose i-th element is the option chosen for batch i. The same option may be used for any number of batches.batches=[12, 9, 7, 6], pack_sizes=[6, 4, 3] → [0, 2, -1, 0]
12 is divisible by 6, so pack size 0. 9 is not divisible by 6 or 4 but is divisible by 3, so pack size 2. 7 fits none, so -1. 6 is divisible by 6, so pack size 0.
batches=[5, 10, 15], pack_sizes=[10, 5, 1] → [1, 0, 1]
For 10, all of 10, 5 and 1 fit, and the earliest one has index 0. For 5 and 15, the first fitting size is 5, at index 1.
batches=[12, 9, 7, 6], pack_sizes=[6, 4, 3]
[0, 2, -1, 0]
Run checks the first 3 tests in your browser. Submit checks all 139 tests on the server, hidden ones included.