#P10759. [BalticOI 2024] Jobs
[BalticOI 2024] Jobs
Background
Translated from BalticOI 2024 Day1 T1。
Problem Description
Currently, you can choose from one-time jobs numbered from to .
Completing job will bring you a profit of euros, and of course, the profit may also be negative.
Some jobs depend on another job. That is, there may be a job with index that must be completed before job can be started. Therefore, if a high-profit job depends on a job with negative profit, the overall gain may look smaller.
If , then job has no dependency.
You currently have euros. You can decide which jobs to do and in what order, as long as you respect the dependencies. In addition, the amount of money you have must never become negative at any time.
Please compute the maximum profit you can obtain by choosing and completing these jobs in some order (and possibly leaving some jobs undone)。
Input Format
The first line contains two integers and , representing the number of jobs and the amount of money you initially have.
The next lines each contain two integers and , representing the profit of job and the index of its prerequisite job. If , then job has no dependency。
Output Format
Your program should output a single integer: the maximum profit you can obtain。
6 1
3 0
-3 1
-5 0
2 1
6 3
-4 5
6
Hint
Choose jobs respectively, and the total profit is .
| Subtask ID | Special Property | Score |
|---|---|---|
| and satisfies Property A | ||
| Satisfies Property A | ||
| No special property |
- Property A: each is either or .
For all testdata, , , , .
Translated by ChatGPT 5