eolymp
bolt
Try our new interface for solving problems
Problems

Job!Job!Job!

Job!Job!Job!

Foreverlin is working in a company. In order to make boss happier, he must work as hard as possible, there are \textbf{n}projects on the todolist. Now is time \textbf{1}, after time \textbf{m}, foreverlin has to go back to the school. Each project has two properties, the finally completion time and the value you can make if you finish this project. At every unit of time, he can choose a project to finish. However, he can only choose one project to do in one unit time, that means in one unit time, he can choose a project to do and finish in this unit time. As the best friend of him ,can you help him to find out how to arrange these projects so that he can make the biggest values. \InputFile There are several test cases,in each test case, there are two numbers \textbf{n}, \textbf{m} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}, \textbf{1} ≤ \textbf{m} ≤ \textbf{1000000}). The next \textbf{n} lines each contains two number \textbf{D\[i\]}, \textbf{V\[i\]} (\textbf{1} ≤ \textbf{D\[i\]} ≤ \textbf{100000}, \textbf{1} ≤ \textbf{V\[i\]} ≤ \textbf{10000}) (\textbf{1} ≤ \textbf{i} ≤ \textbf{n}, \textbf{D\[i\]} means if you choose to do project \textbf{i}, you can not do this after time \textbf{D\[i\]}, \textbf{V\[i\]} means the value of project \textbf{i}). The input will finish with the end of file. \OutputFile For each the case ouput a number means the biggest values.
Time limit 1.5 second
Memory limit 64 MiB
Input example #1
4 10
1 8
1 3
2 10
5 12
Output example #1
30
Source Hunan University 2011 the 7th Programming Contest