Resignation
InterviewTime limit2sMemory limit512 MB
Given each day's consultation length and payment, pick a non-overlapping set of jobs that all finish before day N+1 to maximize total payment.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Brute force, Recursion
- Solved
- No attempts yet
Problem
Junho works as a counselor and plans to resign.
He will leave the company on day , counting today as day 1, so he wants to hold as many consultations as possible during the remaining days.
Junho asked his secretary to book as many consultations as possible, and the secretary booked one consultation per day, each with a different person.
Each consultation has a duration , the number of days it takes to complete, and a payment received for completing it.
Consider the following schedule for .
The consultation booked on day 1 takes 3 days in total and pays 10. The consultation booked on day 5 takes 2 days in total and pays 15.
A consultation can take longer than one day, so Junho cannot hold every consultation. For example, if he holds the consultation on day 1, he cannot hold the consultations on days 2 and 3. If he holds the consultation on day 2, he cannot hold the consultations booked on days 3, 4, 5, and 6.
Also, Junho is no longer at the company on day , so he cannot hold the consultations on days 6 and 7.
The maximum profit before resigning comes from holding the consultations on days 1, 4, and 5, for a profit of .
Write a program that computes the maximum profit Junho can earn by choosing consultations optimally.
Input
The first line contains ().
Each of the next lines contains and separated by a space, given in order from day 1 to day . (, )
Output
Print the maximum profit Junho can earn on the first line.