#P7638. [BalticOI 2006] COIN COLLECTOR (Day 1)

[BalticOI 2006] COIN COLLECTOR (Day 1)

Description

In a country, there are NN coin denominations in circulation, including a 11-cent coin. In addition, there is a banknote with value KK 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 KK-cent banknote in his wallet.

He is in a shop where every item is sold at a price less than KK cents (i.e. 11 cent, 22 cents, 33 cents, \cdots, K1K-1 cents). In this shop, change is given using the following algorithm:

  1. Let the amount of change be AA cents.
  2. Find the largest coin denomination not exceeding AA (call it a BB-cent coin).
  3. Give the customer one BB-cent coin, and subtract BB from AA.
  4. If A=0A = 0, stop; otherwise go back to step 22.

The coin collector buys an item using the KK-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 NN and KK. The next NN lines describe the coins in circulation. Line i+1i+1 contains integers cic_i and did_i, where cic_i is the coin value (in cents). If di=1d_i = 1, it means the collector already has a coin of this denomination; if di=0d_i = 0, it means he does not. The coin values are given in increasing order, i.e. c1<c2<<cNc_1 < c_2 < \cdots < c_N. The first coin is known to be the 11-cent coin, i.e. c1=1c_1 = 1.

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 100%100\% of the testdata, 1N5×1051 \le N \le 5 \times 10^5, 2K1092 \le K \le 10^9, 1ciK1 \le c_i \le K.

Notes

From Baltic Olympiad in Informatics 2006, Day 1:Coins.
Translated and整理 (zhengli) by @求学的企鹅.

Translated by ChatGPT 5