Job Sequencing with Deadlines
Mediumjavapythonccppjavascript
Each of N jobs has an integer deadline and a profit, and takes exactly one unit of time. Only one job runs at a time, starting at time 1. A job earns its profit only if it finishes by its deadline. Maximise total profit.
Input Format
The first line contains an integer N. Each of the next N lines contains two integers deadline and profit.
Output Format
Print the maximum total profit.
Example 1
Input
5 2 100 1 19 2 27 1 25 3 15
Output
142
Explanation: Run job 1 (profit 100) at time 2, job 3 (profit 27) at time 1, job 5 (profit 15) at time 3: 100 + 27 + 15 = 142.
- 1 <= N <= 100000
- 1 <= deadline <= N
- 0 <= profit <= 1000000