cho.sh
Notes
Loading...

Exhibition Hall

Time limit

1s

Memory limit

256 MB

Problem

A company selling paintings is assigned one display stand in an exhibition hall. Every painting is rectangular, all paintings have the same width, and their heights may differ. Each painting also has a price.

The stand has the same width as a painting, so multiple paintings must be placed by overlapping them from front to back. Visitors look at the stand from the front. The visible vertical length of a painting is the vertical length of the part that is not covered by paintings in front of it.

In the illustrated arrangement, if the paintings are stacked from front to back in the order C, B, A, D, a front painting B may completely cover painting A. Then painting A is not visible to visitors at all, while only paintings with at least some exposed part can attract attention.

A visitor is interested in and may buy only a painting whose visible vertical length is at least the integer S. Such a painting is called saleable.

Given the height and price of each painting, arrange the paintings in some order so that the total price of saleable paintings is as large as possible. Compute that maximum total price.

Input

The first line contains the number of paintings N and the integer S used to decide whether a painting is saleable.

Each of the next N lines contains two integers H and C, the height and price of one painting.

The constraints are as follows.

  • 1 <= N <= 300,000
  • 1 <= S <= H <= 20,000,000
  • 1 <= C <= 1,000

Output

Print the maximum possible total price of saleable paintings on the first line.