#P5961. [BalticOI 2006] coin collector钱币收藏家
[BalticOI 2006] coin collector钱币收藏家
Problem Description
In a country, there are types of coins in circulation, including a 1-cent coin. In addition, there is a banknote of value cents, which is larger than the value of any coin. A coin collector wants to collect one sample of every coin value. He already has some coins at home, but now he only takes a single -cent banknote to a shop. The shop sells a total of items, priced at cent, cents, ..., cents.
The shop gives change using the following algorithm:
- Suppose the total change needed is cents.
- Find the largest coin value not exceeding , and let it be a -cent coin.
- Give the customer one -cent coin, then set to .
- If , the algorithm ends; otherwise, go to step 2.
The collector wants to buy one item using his -cent banknote. Please write a program to compute: how many types of coins that he does not yet have can the collector obtain? Under the condition of maximizing the previous answer, what is the most expensive item he can buy?
Input Format
The first line contains two integers and .
The next lines describe the values of the coins in circulation and whether they have already been collected. Line contains an integer and , where is the value of the -th coin. If , the collector already has coin ; if , the collector does not yet have coin . The input is given in increasing order of coin values, i.e., , and the first coin is the 1-cent coin, i.e., .
Output Format
The first line outputs one integer, the maximum number of coin types that the collector can obtain that he did not have before.
The second line outputs one integer, under the condition in the previous question, the price of the most expensive item the collector can buy.
7 25
1 0
2 0
3 1
5 0
10 0
13 0
20 0
3
6
Hint
For all data, , .
Translated by ChatGPT 5