#P7638. [BalticOI 2006] COIN COLLECTOR (Day 1)
[BalticOI 2006] COIN COLLECTOR (Day 1)
Description
In a country, there are coin denominations in circulation, including a -cent coin. In addition, there is a banknote with value cents, which is worth more than any coin denomination. A coin collector wants to collect a sample coin of every denomination. He already has some coins at home, but currently he only has one -cent banknote in his wallet.
He is in a shop where every item is sold at a price less than cents (i.e. cent, cents, cents, , cents). In this shop, change is given using the following algorithm:
- Let the amount of change be cents.
- Find the largest coin denomination not exceeding (call it a -cent coin).
- Give the customer one -cent coin, and subtract from .
- If , stop; otherwise go back to step .
The coin collector buys an item using the -cent banknote.
Your task is to write a program to determine:
- How many different coin denominations can the collector obtain from this transaction that he did not already have in his collection?
- What is the most expensive item the shop can sell him, such that during the change-making process, the number of new denominations obtained is maximized as in the first question?
Input Format
The first line contains integers and . The next lines describe the coins in circulation. Line contains integers and , where is the coin value (in cents). If , it means the collector already has a coin of this denomination; if , it means he does not. The coin values are given in increasing order, i.e. . The first coin is known to be the -cent coin, i.e. .
Output Format
The first line contains one integer: the maximum number of coin denominations that the collector does not have yet but can obtain through one purchase. The second line contains one integer: the highest possible item price such that the change includes the maximum number of new denominations stated in the first line.
7 25
1 0
2 0
3 1
5 0
10 0
13 0
20 0
3
6
Hint
Constraints
For of the testdata, , , .
Notes
From Baltic Olympiad in Informatics 2006, Day 1:Coins.
Translated and整理 (zhengli) by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号