#K90227. Maximum Profit Scheduling
Maximum Profit Scheduling
Maximum Profit Scheduling
You are given a list of projects, where each project takes exactly one day to complete. Each project is represented by two integers: its deadline and its profit. A project with deadline (d) must be completed on or before day (d), and each day can be used to complete at most one project. Your task is to select a subset of projects such that no two projects overlap (i.e., are scheduled on the same day) and the total profit is maximized.
Formally, you are given an integer (n) and (n) pairs of integers ((d_i, p_i)) where:
- (d_i) is the deadline of the (i)-th project, meaning it must be scheduled on some day (j) with (1 \leq j \leq d_i).
- (p_i) is the profit obtained from completing the (i)-th project.
Find the maximum total profit achievable by scheduling these projects optimally.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer (n), the number of projects.
- The next (n) lines each contain two space-separated integers (d) and (p), representing the deadline and profit of a project respectively.
outputFormat
Output a single integer representing the maximum profit that can be achieved by scheduling the projects such that no two projects are done on the same day and each project is completed by its deadline. The output should be printed to standard output (stdout).## sample
4
1 50
2 10
2 20
1 40
70
</p>