Explosive Materials
Time limit1sMemory limit128 MB
Fill each huge truck capacity exactly with unlimited explosive sizes using as few units as possible, or report impossibility.
- Level
Hard8 of 10
- Topics
- Shortest path, Math, Number theory
- Solved
- No attempts yet
Problem
You have taken a contract to transport explosives. You have trucks, and the -th truck has capacity .
For each truck you must plan how to pack it with explosives. Every truck has to be packed exactly full with explosives, because otherwise the materials may be damaged during transport. You have types of explosives with distinct sizes, where the -th type has size , and you can produce as much of each type as you need. Because loading and unloading trucks quickly matters, you want to use as few units of explosive as possible to fill a truck.
For each truck, compute the minimum number of explosive units needed to fill it exactly.
Input
The first line contains two integers and (, ), the number of trucks and the number of explosive types. Each of the next lines contains the size of one explosive type (). Any two types have distinct sizes. Each of the next lines contains the capacity of one truck ().
Output
Print lines. On the -th line print , the minimum number of explosive units needed to fill the -th truck exactly, or the single word NIE if it is impossible.