CF1203F1.Complete the Projects (easy 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 rr units.

Some very rich customers asked him to complete some projects for their companies. To complete the ii-th project, Polycarp needs to have at least aia_i units of rating; after he completes this project, his rating will change by bib_i (his rating will increase or decrease by bib_i) (bib_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.

Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.

In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.

简单版本与困难版本的唯一区别在于:在简单版本中,你需要完成所有项目;而在困难版本中,这并非必需。

Polycarp 是一位非常著名的自由职业者,他当前的评分为 rr 单位。

一些非常富有的客户邀请他为他们的公司完成若干项目。要完成第 ii 个项目,Polycarp 的评分至少需达到 aia_i 单位;完成该项目后,他的评分将变化 bib_i(即评分增加或减少 bib_i 单位)(bib_i 可为正数或负数)。Polycarp 的评分不能低于零,否则人们将不再信任如此低评分的自由职业者。

是否可能完成所有项目?形式化地说,请编写一个程序,判断是否存在一种项目执行顺序,使得 Polycarp 在开始每个项目前均具有足够的评分,并且在完成每个项目后其评分仍为非负数。

换言之,你需要判断是否存在一种项目执行顺序,使得 Polycarp 在开始每个项目前均有足够评分,并且在完成每个项目后其评分均保持非负。

输入格式

The first line of the input contains two integers nn and rr (1≤n≤100,1≤r≤300001 \le n \le 100, 1 \le r \le 30000) — the number of projects and the initial rating of Polycarp, respectively.

The next nn lines contain projects, one per line. The ii-th project is represented as a pair of integers aia_i and bib_i (1≤ai≤300001 \le a_i \le 30000, −300≤bi≤300-300 \le b_i \le 300) — the rating required to complete the ii-th project and the rating change after the project completion.

输入的第一行包含两个整数 nn 和 rr(1≤n≤1001 \le n \le 100,1≤r≤300001 \le r \le 30000),分别表示项目的数量和 Polycarp 的初始评分。

接下来的 nn 行每行描述一个项目。第 ii 个项目由一对整数 aia_i 和 bib_i(1≤ai≤300001 \le a_i \le 30000,−300≤bi≤300-300 \le b_i \le 300)表示,其中 aia_i 是完成第 ii 个项目所需的最低评分,bib_i 是完成该项目后评分的变化量。

输出格式

Print "YES" or "NO".

输出 "YES" 或 "NO"。

输入输出样例

  • 输入#1

    3 4
    4 6
    10 -2
    8 -1

    输出#1

    YES
  • 输入#2

    3 5
    4 -5
    4 -2
    1 3

    输出#2

    YES
  • 输入#3

    4 4
    5 2
    5 -3
    2 1
    4 -2

    输出#3

    YES
  • 输入#4

    3 10
    10 0
    10 -10
    30 0

    输出#4

    NO

说明/提示

In the first example, the possible order is: 1,2,31, 2, 3.

In the second example, the possible order is: 2,3,12, 3, 1.

In the third example, the possible order is: 3,1,4,23, 1, 4, 2.

在第一个例子中,可能的顺序是:1,2,31, 2, 3。

在第二个例子中,可能的顺序是:2,3,12, 3, 1。

在第三个例子中,可能的顺序是:3,1,4,23, 1, 4, 2。

输入解题思路,AI测评打分。不知道怎么写?

首页