Logo
(追記) (追記ここまで)

31968번 - Jobs 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB97353141.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ドル ≤ N ≤ 3 \cdot 10^5$
  • 0ドル ≤ s ≤ 10^{18}$
  • $-10^9 ≤ x_i ≤ 10^9$ (for all 1ドル ≤ i ≤ N$)
  • 0ドル ≤ p_i < i$ (for all 1ドル ≤ i ≤ N$)

서브태스크

번호배점제한
111

$s = 10^{18}$.

214

$N ≤ 2000$ and for all jobs, either $p_i = 0,ドル or $p_i = i - 1$.

315

For all jobs, either $p_i = 0,ドル or $p_i = i - 1$.

429

$N ≤ 2000$.

531

No additional constraints.

예제 입력 1

6 1
3 0
-3 1
-5 0
2 1
6 3
-4 5

예제 출력 1

6

To maximize profit, you should pick jobs 1ドル,ドル 4ドル,ドル 3ドル$ and 5ドル$ in the following order:

  • Job 1ドル$: money 1ドル \rightarrow 4,ドル
  • Job 4ドル$ (prerequisite 1ドル$ complete): money 4ドル \rightarrow 6,ドル
  • Job 3ドル$: money 6ドル \rightarrow 1,ドル
  • Job 5ドル$ (prerequisite 3ドル$ complete): money 1ドル \rightarrow 7$.

Overall, the total profit is 7ドル - 1 = 6$ (current money minus starting money).

힌트

출처

Olympiad > Baltic Olympiad in Informatics > BOI 2024 A번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /