| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 97 | 35 | 31 | 41.892% |
You have a successful business where you make money by completing jobs for your clients. Currently, you can choose from N one-time jobs, numbered from 1ドル$ to $N$.
Completing job $i$ will make you a profit of $x_i$ euros. The profit may also be negative ($x_i < 0$).
Some jobs depend on another job. That is, there may be a job numbered $p_i$ that must be completed before the $i$-th job can be started. Hence, a job with a large profit may be less attractive than it seems if it depends on a job with a negative profit. If $p_i = 0,ドル the $i$-th job has no dependency.
You currently have $s$ euros and can decide which jobs to do and in which order to do them, as long as the dependencies are respected. Moreover, the amount of money you own may not become negative at any point.
Calculate the maximum profit you can make by choosing to complete some (possibly none) of the $N$ jobs in a selected order.
The first line contains two integers $N$ and s – the number of jobs and the amount of money you initially own respectively.
Then, $N$ lines follow. The $i$-th of them contains two integers $x_i$ and $p_i$ – the profit and the number of the prerequisite job for the $i$-th job, respectively. If $p_i = 0,ドル the $i$-th job does not have a job dependency.
Your program should output a single integer – the maximum profit that you can make.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 11 | $s = 10^{18}$. |
| 2 | 14 | $N ≤ 2000$ and for all jobs, either $p_i = 0,ドル or $p_i = i - 1$. |
| 3 | 15 | For all jobs, either $p_i = 0,ドル or $p_i = i - 1$. |
| 4 | 29 | $N ≤ 2000$. |
| 5 | 31 | No additional constraints. |
6 1 3 0 -3 1 -5 0 2 1 6 3 -4 5
6
To maximize profit, you should pick jobs 1ドル,ドル 4ドル,ドル 3ドル$ and 5ドル$ in the following order:
Overall, the total profit is 7ドル - 1 = 6$ (current money minus starting money).