Under construction

Still being built. Things may change

Coin

Interview

Time limit2sMemory limit1024 MB

Summary
Find the fewest coins from unlimited denominations whose values sum to V and weights sum to W.
Level

Medium4 of 10

Topics
Dynamic programming
Solved
No attempts yet

Problem

A currency is issued in NN coin denominations. Denomination ii has a value of viv_i cents and a weight of wiw_i grams (1≤i≤N1 \le i \le N). Two denominations can share the same value or the same weight, but not both.

You are given VV and WW. Find MM, the smallest number of coins whose values add up to exactly VV cents and whose weights add up to exactly WW grams. If no such collection of coins exists, MM is 00. Every denomination has an unlimited supply of coins.

Input

The first line contains the number of denominations NN, the target value VV, and the target weight WW, separated by spaces.

Each of the next NN lines contains the value viv_i and the weight wiw_i of one denomination, separated by a space.

1≤N≤201 \le N \le 20, 1≤V≤1501 \le V \le 150, 1≤W≤1501 \le W \le 150, 1≤vi≤1501 \le v_i \le 150, 1≤wi≤1501 \le w_i \le 150.

Output

Print MM on a single line. Print 00 when no collection of coins reaches both totals.

Examples2

  1. Example 1

    Input
    8 141 4
    1 1
    2 1
    4 1
    8 1
    16 1
    32 1
    64 1
    128 1
    
    Expected output
    4
    
  2. Example 2

    Input
    4 11 17
    12 3
    4 7
    8 10
    21 9
    
    Expected output
    0