PivotOJ

Jobs

시간 제한: 2000ms메모리 제한: 1024MB출처: BOI 2024BOJ 31968

문제

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 11 to NN.

Completing job ii will make you a profit of xix_i euros. The profit may also be negative (xi<0x_i < 0).

Some jobs depend on another job. That is, there may be a job numbered pip_i that must be completed before the ii-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 pi=0p_i = 0, the ii-th job has no dependency.

You currently have ss 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 NN jobs in a selected order.

입력

The first line contains two integers NN and s – the number of jobs and the amount of money you initially own respectively.

Then, NN lines follow. The ii-th of them contains two integers xix_i and pip_i – the profit and the number of the prerequisite job for the ii-th job, respectively. If pi=0p_i = 0, the ii-th job does not have a job dependency.

출력

Your program should output a single integer – the maximum profit that you can make.

예제

예제 1

입력
6 1
3 0
-3 1
-5 0
2 1
6 3
-4 5
출력
6
코드를 제출하려면 로그인하세요.