# [01 Backpack]hihocoder_1038_01 Backpack

Source: Internet
Author: User
Time limit: 20000ms single point time limit: 1000ms memory limit: 256MB description

Say then last week's story, Small hi and small ho struggled to finally get the vast number of lottery tickets! And now, it's time for Little Ho to pick up the reward!

Small Ho now has M-ticket, and the prize area has n prizes, respectively labeled 1 to N, of which the first prize of the need (i) to redeem the lottery, but also can only redeem once, in order to make the hard-won lottery not wasted, small ho to each of the prizes are assessed points, The score value of the prize for the I-item is value (i), which indicates his preference for the prize. Now he wants to know which prizes can be changed by virtue of the lotteries in his hand, so that the sum of the prizes ' preferences can be maximized.

Tip One: Reasonable abstract problem, define state is the most critical step in dynamic planning

Hint two: said to reduce the time consumption, let's see how to reduce the space consumption

Input

Each test point (input file) has and has only one set of test data.

The first act of each set of test data is two positive integers n and m, indicating the number of prizes, and the number of lotteries in small Ho's hands.

The next n lines describe each line describing a prize, where I behaves two integers need (i) and value (i), meaning as described earlier.

Test Data Assurance

For 100% of data, the value of n does not exceed the value of 500,m no more than 10^5

For 100% of data, need (i) does not exceed 2*10^5, value (i) does not exceed 10^3

Output

For each set of test data, output an integer ans that represents the total preference value that small ho can get.

Sample input
`5 1000144 990487 436210 673567 581056 897`
Sample output
`2099`

[01 Backpack]hihocoder_1038_01 Backpack

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.