This page is still under construction.

Parts of this page are still being built. What you see may change.

Buying Hay

Interview

Time limit1sMemory limit128 MB

Summary
Given N package types with unlimited supply, each weighing P_i and costing C_i, find the minimum total cost to buy at least H pounds of hay.
Level

Medium6 of 10

Topics
Dynamic programming, Greedy, Math, Brute force
Solved
No attempts yet

Problem

Farmer John is running low on supplies and needs to buy at least HH (1≤H≤50,0001 \le H \le 50{,}000) pounds of hay for his cows.

There are NN (1≤N≤1001 \le N \le 100) hay suppliers, conveniently numbered 11 through NN. Supplier ii sells packages that each contain PiP_i (1≤Pi≤5,0001 \le P_i \le 5{,}000) pounds of hay at a price of CiC_i (1≤Ci≤5,0001 \le C_i \le 5{,}000) dollars. Every supplier has an unlimited number of packages, and each package must be bought whole (packages cannot be split).

Help Farmer John find the minimum cost required to buy at least HH pounds of hay.

Input

  • Line 1: Two space-separated integers NN and HH.
  • Lines 2 to N+1N+1: Line i+1i+1 contains two space-separated integers PiP_i and CiC_i for supplier ii.

Output

  • Line 1: A single integer, the minimum cost Farmer John must pay to obtain at least HH pounds of hay.

Hint

For instance, buying three packages from the second supplier (55 pounds each at 33 dollars) yields 1515 pounds for a total cost of 99 dollars.

Examples2

  1. Example 1

    Input
    2 15
    3 2
    5 3
    
    Expected output
    9
    
  2. Example 2

    Input
    1 10
    2 3
    
    Expected output
    15