CF1203F2.Complete the Projects (hard version)
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai units of rating; after he completes this project, his rating will change by bi (his rating will increase or decrease by bi) (bi 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.
简单版本与困难版本的唯一区别在于:在简单版本中,你需要完成所有项目;而在困难版本中,这并非必需。
Polycarp 是一位非常著名的自由职业者,他当前的评分为 r 单位。
一些非常富有的客户邀请他为他们的公司完成若干项目。要完成第 i 个项目,Polycarp 必须至少拥有 ai 单位的评分;完成该项目后,他的评分将变化 bi(即评分增加或减少 bi 单位)(bi 可为正数或负数)。Polycarp 的评分不得低于零,否则人们将不再信任如此低评分的自由职业者。
Polycarp 可以自行选择完成项目的顺序;此外,他甚至可以完全跳过某些项目。
为了获得更多经验(当然还有金钱),Polycarp 希望选出一个尽可能大的项目子集,并确定其完成顺序,使得他在开始每个项目前都拥有足够的评分,且在完成每个项目后评分仍为非负数。
你的任务是计算满足上述条件的项目子集的最大可能大小。
输入格式
The first line of the input contains two integers n and r (1≤n≤100,1≤r≤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 ai and bi (1≤ai≤30000, −300≤bi≤300) — the rating required to complete the i-th project and the rating change after the project completion.
输入的第一行包含两个整数 n 和 r(1≤n≤100,1≤r≤30000),分别表示项目的数量和 Polycarp 的初始评分。
接下来的 n 行每行描述一个项目。第 i 个项目由一对整数 ai 和 bi(1≤ai≤30000,−300≤bi≤300)表示,其中 ai 是完成第 i 个项目所需的最低评分,bi 是完成该项目后评分的变化量。
输出格式
Print one integer — the size of the maximum possible subset (possibly, empty) of projects Polycarp can choose.
输出一个整数——Polycarp 可选择的项目最大可能子集的大小(该子集可以为空)。
输入输出样例
输入#1
3 4 4 6 10 -2 8 -1
输出#1
3
输入#2
5 20 45 -6 34 -15 10 34 1 27 40 -45
输出#2
5
输入#3
3 2 300 -300 1 299 1 123
输出#3
3
输入解题思路,AI测评打分。不知道怎么写?