Under construction

Still being built. Things may change

How to Eat at a Buffet

Interview

Time limit2sMemory limit512 MB

Summary
Given a plate area and items with value per area and available area, pick fractions to maximize total value on the plate.
Level

Medium4 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

Some restaurants sell all you can eat buffet lunches and dinners instead of a fixed seated meal. For a hungry student that is usually the better deal. Alice likes buffet meals, but she always worries about how to fill her plate. She values each of the nn items on the menu differently, and she wants the total value on her plate to be as large as possible, limited by the area of the plate and by how much of each item is available. The items on the menu are easy to divide, so Alice can take an arbitrary fraction of each dish. Help her fill her plate.

Input

The input consists of n+2n + 2 lines.

  • The first line contains the number nn of different items on the menu.
  • The second line contains the area aa of Alice's plate, an integer in mm2^2.
  • Each of the next nn lines describes one menu item as two integers separated by a space. The first integer is the value viv_i of item ii per mm2^2 as perceived by Alice. The second integer is the area aia_i, in mm2^2, that item ii would occupy if Alice moved all of it onto her plate.

Limits

  • 1≤n≤10001 \le n \le 1000
  • 0≤a≤1000000 \le a \le 100000
  • For every ii with 0≤i≤n−10 \le i \le n - 1:
    • 0≤vi≤1000 \le v_i \le 100
    • 0≤ai≤1000000000 \le a_i \le 100000000

Output

Print a single line with one integer, the maximal value that Alice can fit on her plate. Every area and every unit value is an integer, so this maximum is always an integer.

Examples1

  1. Example 1

    Input
    5
    1000
    50 230
    80 12
    10 1000000
    25 450
    2 50
    
    Expected output
    26790