Preparando MOJI

Selling Souvenirs

2000ms 262144K

Description:

After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.

This morning, as usual, Petya will come to the market. Petya has n different souvenirs to sell; ith souvenir is characterised by its weight wi and cost ci. Petya knows that he might not be able to carry all the souvenirs to the market. So Petya wants to choose a subset of souvenirs such that its total weight is not greater than m, and total cost is maximum possible.

Help Petya to determine maximum possible total cost.

Input:

The first line contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 300000) — the number of Petya's souvenirs and total weight that he can carry to the market.

Then n lines follow. ith line contains two integers wi and ci (1 ≤ wi ≤ 3, 1 ≤ ci ≤ 109) — the weight and the cost of ith souvenir.

Output:

Print one number — maximum possible total cost of souvenirs that Petya can carry to the market.

Sample Input:

1 1
2 1

Sample Output:

0

Sample Input:

2 2
1 3
2 2

Sample Output:

3

Sample Input:

4 3
3 10
2 7
2 8
1 1

Sample Output:

10

Informação

Codeforces

Provedor Codeforces

Código CF808E

Tags

binary searchdpgreedyternary search

Submetido 0

BOUA! 0

Taxa de BOUA's 0%

Datas 09/05/2023 09:15:22

Relacionados

Nada ainda