Problem F2

Statement
Copy Copied
Description:
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.

Polycarp is a very famous freelancer. His current rating is $$$r$$$ units.

Some very rich customers asked him to complete some projects for their companies. To complete the $$$i$$$-th project, Polycarp needs to have at least $$$a_i$$$ units of rating; after he completes this project, his rating will change by $$$b_i$$$ (his rating will increase or decrease by $$$b_i$$$) ($$$b_i$$$ can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.

Polycarp can choose the order in which he completes projects. Furthermore, he can even skip some projects altogether.

To gain more experience (and money, of course) Polycarp wants to choose the subset of projects having maximum possible size and the order in which he will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.

Your task is to calculate the maximum possible size of such subset of projects.

Input Format:
The first line of the input contains two integers $$$n$$$ and $$$r$$$ ($$$1 \le n \le 100, 1 \le r \le 30000$$$) — the number of projects and the initial rating of Polycarp, respectively.

The next $$$n$$$ lines contain projects, one per line. The $$$i$$$-th project is represented as a pair of integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i \le 30000$$$, $$$-300 \le b_i \le 300$$$) — the rating required to complete the $$$i$$$-th project and the rating change after the project completion.

Output Format:
Print one integer — the size of the maximum possible subset (possibly, empty) of projects Polycarp can choose.

Note:
None

Submissions

IDLanguageExit CodeTimestampCodeStdoutStderrRetry
6158 go 0 2026-03-27T06:26:29.884199Z View View View Retry

Evaluations

Eval IDRun IDProviderModelLangSuccessTimestampPromptResponseStdoutStderrRetry
4281 20260327-220005 openai gpt-5.4 go true 2026-03-28T00:18:41.903415Z View View View View Retry
4186 20260326-230008 gemini gemini-3.1-pro-preview go false 2026-03-27T01:46:26.236496Z View View View View Retry
4125 20260326-230008 gemini gemini-3.1-pro-preview go false 2026-03-27T00:07:07.944705Z View View View View Retry