Auto-Coin-o-Matic
시간 제한2초메모리 제한2048 MB
서로 다른 액면가의 동전이 시간에 따라 하나씩 제거될 때, 각 질의마다 값 v를 정확히 만드는 최소 동전 개수를 구하고 불가능하면 -1을 출력한다.
문제
It's finally here! The day you unveil your new invention, the Auto-Coin-o-Matic! You watch with glee and anxiety as people insert their card into the machine, type in the amount they want, and get exact change out with the fewest number of coins.
But was it actually the fewest number of coins? That's how it was programmed, but what if you had a bug? It's okay, you're watching. You decide to randomly pick some transactions and double check that what the machine gave out is indeed the fewest number of coins possible. But, oh no, the machine is running out of certain types of coins! Will it still work correctly?
입력
The input starts with two integers and (, ).
The next line contains integers, () representing the denominations of coins available initially. It is guaranteed that all denominations are unique.
The next lines contain a character (c\in \\{Q, X\\}) and an integer (), where is the type of event and is the value of the event.
-
If is the character
Q, this is a query and the output should be the minimum number of coins needed to give out exactly . It is guaranteed that there will be at least one query.If it is not possible to make exactly with the available denominations, output instead.
-
If is the character
X, this means the machine is out of coins of denomination . All queries after this point cannot use this denomination. It is guaranteed that eachXevent corresponds to a denomination which the machine currently has in stock.
출력
Output lines, where is the number of query events (Q). On the th line, output the fewest number of coins needed to give change for the th query, or if this is impossible.