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.

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.


-----Input-----

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-----

Print "YES" or "NO".


-----Examples-----
Input
3 4
4 6
10 -2
8 -1

Output
YES

Input
3 5
4 -5
4 -2
1 3

Output
YES

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

Output
YES

Input
3 10
10 0
10 -10
30 0

Output
NO



-----Note-----

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

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

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

Difficulty: HARD

Solutions:
import sys
input = sys.stdin.readline
from math import gcd, sqrt
(n, r) = map(int, input().split())
l = []
for _ in range(n):
	l.append(list(map(int, input().split())))
p = 0
while p < n:
	if l[p][0] <= r and l[p][1] >= 0:
		r += l[p][1]
		l = l[:p] + l[p + 1:]
		p = 0
		n -= 1
	else:
		p += 1
if l == []:
	print('YES')
	exit(0)
ans = True
q = len(l)
for i in range(q):
	l[i][0] = max(l[i][0], -l[i][1])
l = sorted(l, key=lambda x: x[0] + x[1])
l.reverse()
for i in range(len(l)):
	if l[i][0] > r:
		ans = False
		break
	else:
		r += l[i][1]
if ans and r >= 0:
	print('YES')
else:
	print('NO')


from sys import stdin
from sys import setrecursionlimit as SRL
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda : map(int, rd().strip().split())
(n, r) = rrd()
pos = []
neg = []
for i in range(n):
	(a, b) = rrd()
	if b < 0:
		neg.append([a, b])
	else:
		pos.append([a, b])
pos.sort(key=lambda x: x[0])
neg.sort(key=lambda x: x[0] + x[1])
ans = 0
for (a, b) in pos:
	if r >= a:
		r += b
		ans += 1
	else:
		break
dp = [[0] * 105 for _i in range(60005)]
for i in range(r + 10):
	for j in range(len(neg)):
		if i >= neg[j][0] and i + neg[j][1] >= 0:
			if j:
				dp[i][j] = max(dp[i][j], dp[i + neg[j][1]][j - 1] + 1, dp[i][j - 1])
			else:
				dp[i][j] = 1
		elif j:
			dp[i][j] = dp[i][j - 1]
print('YES' if dp[r][len(neg) - 1] + ans == n else 'NO')


(n, r) = map(int, input().split())
arr1 = []
arr2 = []
for i in range(n):
	(x, y) = map(int, input().split())
	if y >= 0:
		arr1.append((x, y))
	else:
		arr2.append((x, y))
arr1.sort()
arr2.sort(reverse=True)
currval = r
flag = 0
for i in range(len(arr1)):
	if arr1[i][0] > currval:
		print('NO')
		exit(0)
	else:
		currval += arr1[i][1]
tempval = currval
mark = [0] * len(arr2)
countx = 0
finalans = 0
while countx < len(arr2):
	flag = -1
	for i in range(len(arr2)):
		if mark[i] == 0 and currval >= arr2[i][0]:
			tempflag = 0
			for j in range(len(arr2)):
				if j != i and mark[j] == 0:
					if currval + arr2[i][1] < arr2[j][0]:
						tempflag = 1
						break
			if tempflag == 0:
				flag = i
				break
	if flag == -1:
		finalans = 1
		break
	else:
		currval += arr2[flag][1]
		mark[flag] = 1
		countx += 1
if currval < 0:
	finalans = 1
if finalans == 0:
	print('YES')
else:
	mark = [0] * len(arr2)
	countx = 0
	finalans = 0
	currval = tempval
	while countx < len(arr2):
		flag = -1
		for i in range(len(arr2)):
			if mark[i] == 0 and currval >= arr2[i][0]:
				tempflag = 0
				for j in range(len(arr2)):
					if j != i and mark[j] == 0:
						if currval + arr2[i][1] < arr2[j][0]:
							tempflag = 1
							break
				if tempflag == 0:
					flag = i
		if flag == -1:
			print('NO')
			exit(0)
			break
		else:
			currval += arr2[flag][1]
			mark[flag] = 1
			countx += 1
	if currval < 0:
		print('NO')
	else:
		print('YES')


(N, m) = map(int, input().split())
p = []
n = []
for i in range(N):
	a = list(map(int, input().split()))
	a[0] = max(a[0], -a[1])
	if a[1] < 0:
		n.append([a[0] + a[1], a[0], a[1]])
	else:
		p.append(a)
p.sort()
n.sort(reverse=True)
ans = 'YES'
c = m
for i in range(len(p)):
	if p[i][0] <= c:
		c += p[i][1]
	else:
		ans = 'NO'
		break
for i in range(len(n)):
	if n[i][1] <= c:
		c += n[i][2]
	else:
		ans = 'NO'
		break
print(ans)


import sys
from collections import defaultdict as dd
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
(n, r) = ri()
eventspos = []
eventsneg = []
for i in range(n):
	temp = ri()
	if temp[1] >= 0:
		eventspos.append(temp)
	else:
		eventsneg.append(temp)
eventspos.sort()
eventsneg.sort(key=lambda x: x[0] + x[1])
eventsneg.reverse()
status = 1
ans = 0
for i in range(len(eventspos)):
	if eventspos[i][0] <= r:
		r += eventspos[i][1]
		ans += 1
	else:
		status = 0
check = [0 for i in range(r + 1)]
for i in range(len(eventsneg)):
	for j in range(eventsneg[i][0], r + 1):
		if j + eventsneg[i][1] >= 0:
			check[j + eventsneg[i][1]] = max(check[j + eventsneg[i][1]], check[j] + 1)
if max(check) + ans == n:
	print('YES')
else:
	print('NO')


import sys
(n, r) = map(int, input().split())
plus = []
minus = []
for (a, b) in (map(int, l.split()) for l in sys.stdin):
	if b >= 0:
		plus.append((a, b))
	else:
		minus.append((a, b))
plus.sort()
for (a, b) in plus:
	if r < a:
		print('NO')
		exit()
	r += b
minus.sort(key=lambda x: x[0] + x[1], reverse=True)
for (a, b) in minus:
	if r < a:
		print('NO')
		exit()
	r += b
print('YES' if r >= 0 else 'NO')


from collections import defaultdict
(n, r) = map(int, input().split())
pos = []
neg = []
for _ in range(n):
	(a, b) = map(int, input().split())
	if b > 0:
		pos.append((a, b))
	else:
		neg.append((a, b))
pos.sort()
has = True
for i in pos:
	(a, b) = i
	if r < a:
		has = False
		break
	r += b
if not has:
	print('NO')
else:
	neg.sort(key=lambda x: x[0] + x[1], reverse=True)

	def can_complete():
		for i in range(len(neg)):
			if r >= abs(neg[i][0]):
				return i
		else:
			return -1
	cnt = 0
	while True:
		result = can_complete()
		if result == -1:
			break
		r += neg[result][1]
		if r < 0:
			break
		del neg[result]
	if neg != []:
		print('NO')
	else:
		print('YES')


(n, r) = map(int, input().split())
plus = []
minn = []
for i in range(0, n):
	temp = list(map(int, input().split()))
	if temp[1] <= 0:
		temp.append(temp[0] + temp[1])
		minn.append(temp)
	else:
		plus.append(temp)
plus.sort()
minn.sort(reverse=True, key=lambda x: x[2])
flag = True
for i in plus:
	if i[0] <= r:
		r += i[1]
	else:
		flag = False
		break
if flag:
	for i in minn:
		if i[0] <= r:
			r += i[1]
		else:
			flag = False
			break
if flag and r >= 0:
	print('YES')
else:
	print('NO')


(n, r) = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]

def solve1(cur, arr):
	flg = True
	while len(arr) > 0:
		max_inc = -9999
		choose = None
		for (a, b) in arr:
			if cur >= a and max_inc < b:
				max_inc = b
				choose = a
		if choose is None:
			flg = False
			break
		cur += max_inc
		arr.remove([choose, max_inc])
	if flg == False:
		return ('NO', None)
	return ('YES', cur)

def solve2(cur, arr2):
	flg = True
	while len(arr2) > 0:
		min_inc = 0
		choose = None
		for (a, b) in arr2:
			if cur - b >= a and b < min_inc:
				min_inc = b
				choose = a
		if choose is None:
			flg = False
			break
		cur -= min_inc
		arr2.remove([choose, min_inc])
	if flg == False:
		return ('NO', None)
	return ('YES', cur)
arr1 = [[x, y] for (x, y) in arr if y >= 0]
arr2 = [[x, y] for (x, y) in arr if y < 0]
(ans, cur) = solve1(r, arr1)
if ans == 'NO':
	print('NO')
else:
	cur += sum([x[1] for x in arr if x[1] < 0])
	if cur < 0:
		print('NO')
	else:
		(ans, cur) = solve2(cur, arr2)
		if ans == 'NO':
			print('NO')
		else:
			print('YES')


(num_p, rating) = map(int, input().split(' '))

def do_projs(L, rating):
	for (r, change) in L:
		if r > rating:
			return ('NO', rating)
		if r <= rating:
			rating += change
		if rating < 0:
			return ('NO', rating)
	return ('YES', rating)
projl = []
for project in range(num_p):
	projl.append(tuple(map(int, input().split(' '))))
projl.sort(key=lambda i: i[1], reverse=True)
for (idx, proj) in enumerate(projl):
	if proj[1] <= 0:
		break
projl_pos = projl[:idx]
projl_neg = projl[idx:]
projl_pos.sort(key=lambda i: i[0], reverse=False)
mark = False
(res, rating) = do_projs(projl_pos, rating)
if res == 'NO':
	print(res)
else:
	projl_neg.sort(key=lambda i: i[0] + i[1], reverse=True)
	(res, rating) = do_projs(projl_neg, rating)
	print(res)


from math import *

def nextInt():
	return int(input())

def nextInts():
	return list(map(int, input().split()))

def YN(x):
	return 'YES' if x else 'NO'

def solve():
	(n, r) = nextInts()
	pos = []
	neg = []
	for i in range(n):
		(a, b) = nextInts()
		a = max(a, -b)
		if b >= 0:
			pos.append((a, b))
		else:
			neg.append((a, b))
	pos.sort(key=lambda x: x[0])
	neg.sort(key=lambda x: -(x[0] + x[1]))
	for t in pos:
		if r < t[0]:
			return False
		r += t[1]
	for t in neg:
		if r < t[0]:
			return False
		r += t[1]
	return True
print(YN(solve()))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
from decimal import *

def solve():

	class SegmentTree:

		def __init__(self, data, default=0, func=max):
			self._default = default
			self._func = func
			self._len = len(data)
			self._size = _size = 1 << (self._len - 1).bit_length()
			self.data = [default] * _size + data + [default] * (_size - self._len)
			for i in range(_size - 1, -1, -1):
				self.data[i] = func(self.data[2 * i], self.data[2 * i + 1])

		def __delitem__(self, idx):
			self[idx] = self._default

		def __getitem__(self, idx):
			return self.data[idx + self._size]

		def __setitem__(self, idx, value):
			idx += self._size
			self.data[idx] = value
			idx >>= 1
			while idx:
				self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
				idx >>= 1

		def __len__(self):
			return self._len

		def query(self, start, stop):
			start += self._size
			stop += self._size
			res_left = res_right = self._default
			while start < stop:
				if start & 1:
					res_left = self._func(res_left, self.data[start])
					start += 1
				if stop & 1:
					stop -= 1
					res_right = self._func(self.data[stop], res_right)
				start >>= 1
				stop >>= 1
			return self._func(res_left, res_right)

		def __repr__(self):
			return 'SegmentTree({0})'.format(self.data)
	(n, r) = sep()
	posrat = []
	negrat = []
	for _ in range(n):
		(a, b) = sep()
		if b >= 0:
			posrat.append((a, b))
		else:
			negrat.append((a, b))
	posrat.sort()

	def f(x):
		return x[0] + x[1]
	negrat.sort(reverse=True, key=f)
	cr = r
	for i in posrat:
		(ai, bi) = i
		if ai > cr:
			print('NO')
			return
		else:
			cr += bi
	for i in negrat:
		(ai, bi) = i
		if ai > cr:
			print('NO')
			return
		else:
			cr += bi
	if cr >= 0:
		print('YES')
		return
	print('NO')
solve()


l = list(map(int, input().split()))
n = l[0]
r = l[1]
pos = []
neg = []
for _ in range(n):
	l = list(map(int, input().split()))
	if l[1] >= 0:
		pos.append((l[0], l[1]))
	else:
		neg.append((l[0], l[1]))
pos.sort(key=lambda k: k[0])
bad = False
for item in pos:
	if r >= item[0]:
		r += item[1]
	else:
		bad = True
		break
neg.sort(key=lambda k: -(k[0] - r + k[1]))
for item in neg:
	if r >= item[0]:
		r += item[1]
	else:
		bad = True
		break
if r < 0:
	bad = True
print('YES' if bad == False else 'NO')


def sign(x):
	return (x > 0) - (x < 0)

def key(ab):
	(a, b) = ab
	return (2, -a - b) if b < 0 else (1, a)

def main():
	(n, r) = list(map(int, input().split()))
	for (a, b) in sorted((tuple(map(int, input().split())) for _ in range(n)), key=key):
		if r < a:
			r = -1
			break
		r += b
	if r < 0:
		print('NO')
	else:
		print('YES')
main()


def solve(n, r, projects):
	pos = []
	neg = []
	for (a, b) in projects:
		if b < 0:
			neg.append((a, b))
		else:
			pos.append((a, b))
	pos.sort()
	neg.sort(key=lambda t: -t[0] - t[1])
	for (a, b) in pos:
		if r >= a:
			r += b
		else:
			return False
	for (a, b) in neg:
		if r >= a:
			r += b
			if r < 0:
				return False
		else:
			return False
	return True
(n, r) = map(int, input().split())
projects = []
for i in range(n):
	(a, b) = map(int, input().split())
	projects.append([a, b])
if solve(n, r, projects):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
pos = []
neg = []
for i in range(n):
	l = list(map(int, input().split()))
	if l[1] >= 0:
		pos.append(l)
	else:
		neg.append(l)
pos.sort()
f = 0
for i in pos:
	if m >= i[0]:
		m += i[1]
	else:
		f = 1
		break
else:
	for i in neg:
		i[0] = i[0] + i[1]
		i[1] = i[0] - i[1]
	neg.sort(reverse=True)
	for i in neg:
		if m >= i[1]:
			m += i[0] - i[1]
		else:
			f = 1
			break
		if m < 0:
			f = 1
			break
if f == 0:
	print('YES')
else:
	print('NO')


def fun():
	(n, r) = list(map(int, input().strip().split()))
	pos = []
	neg = []
	for i in range(n):
		project = list(map(int, input().strip().split()))
		if project[1] >= 0:
			pos.append(project)
		else:
			project[0] = max(project[0], -project[1])
			neg.append(project)
	pos = sorted(pos, key=lambda p: p[0])
	for p in pos:
		if p[0] > r or r < 0:
			return 'NO'
		r += p[1]
	neg = sorted(neg, key=lambda p: p[0] + p[1], reverse=True)
	for p in neg:
		if p[0] > r or r < 0:
			return 'NO'
		r += p[1]
	return 'YES'
print(fun())


(n, r) = map(int, input().split())
a = []
for i in range(n):
	a.append([int(j) for j in input().split()])
flag = True
while flag:
	flag = False
	for i in a:
		if r >= i[0] and i[1] >= 0:
			flag = True
			r += i[1]
			a.remove(i)
			break
while a:
	mx = max(a, key=lambda x: x[0] + x[1])
	if r < mx[0]:
		exit(print('NO'))
	r += mx[1]
	a.remove(mx)
	if r < 0:
		exit(print('NO'))
print('YES')


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getArr():
	return list(map(int, input().split()))

def getStr():
	return input().strip()

def ObrabotkaPlus():
	global PLUS, res, R
	keys = list(PLUS.keys())
	keys.sort()
	for k in keys:
		if k <= R:
			R += sum(PLUS[k])
		else:
			res = 'NO'
			break

def ObrabotkaNull():
	global m0, res, R
	if m0 > R:
		res = 'NO'

def ObrabotkaMinus2():
	global R, res, MINUS
	keys = list(MINUS.keys())
	keys.sort(reverse=True)
	for k in keys:
		for x in MINUS[k]:
			if R < x[0]:
				res = 'NO'
				break
			else:
				R += x[1]
				if R < 0:
					res = 'NO'
					break
		if res == 'NO':
			break
res = 'YES'
(N, R) = getVars()
m0 = 0
PLUS = {}
MINUS = {}
MINUS3 = []
for i in range(N):
	(a, b) = getVars()
	if b > 0:
		if a <= R:
			R += b
		else:
			if a not in PLUS:
				PLUS[a] = []
			PLUS[a].append(b)
	elif b == 0:
		m0 = max(m0, a)
	else:
		key = max(a, -b) + b
		if key not in MINUS:
			MINUS[key] = []
		MINUS[key].append([a, b])
ObrabotkaPlus()
if res == 'YES':
	ObrabotkaNull()
if res == 'YES':
	ObrabotkaMinus2()
print(res)


import collections, heapq, bisect, math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def solve(r, A):
	r = int(r)
	while A:
		opt = max(range(len(A)), key=lambda x: A[x][1] if r >= A[x][0] else -400)
		if A[opt][0] > r:
			return 'NO'
		if A[opt][1] < 0:
			A.sort(key=lambda x: max(x[0], -x[1]) + x[1], reverse=True)
			for a in A:
				if r < a[0]:
					return 'NO'
				r += a[1]
			return 'YES'
		r += A[opt][1]
		(A[opt], A[-1]) = (A[-1], A[opt])
		A.pop()
	return 'YES'
q = 1
(n, r) = input().split(' ')
tests = []
for test in range(int(n)):
	tests.append([int(p) for p in input().split(' ')])
print(solve(r, tests))


def myFunc(e):
	return e[0] + e[1]
(count, rating) = map(int, input().split())
goodJob = []
badJob = []
for i in range(count):
	(a, b) = map(int, input().split())
	if b >= 0:
		goodJob.append([a, b])
	else:
		badJob.append([a, b])
goodJob.sort()
badJob.sort(reverse=True, key=myFunc)
flag = False
for job in goodJob:
	if job[0] <= rating:
		rating += job[1]
	else:
		flag = True
		break
if not flag:
	for job in badJob:
		if job[0] <= rating:
			rating += job[1]
		else:
			flag = True
			break
if rating < 0:
	flag = True
print('NO') if flag else print('YES')


(n, r) = map(int, input().split())
Pos = list()
Neg = list()
for i in range(n):
	(a, b) = map(int, input().split())
	if b < 0:
		Neg.append([a + b, a, b])
	else:
		Pos.append([a, b])
Pos.sort()
for (a, b) in Pos:
	if r < a:
		print('NO')
		exit()
	r += b
Neg = sorted(Neg, reverse=True)
for (_, a, b) in Neg:
	if r < a:
		print('NO')
		exit()
	r += b
print('YES' if r >= 0 else 'NO')


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_1():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def inps():
	return sys.stdin.readline()

def inpsl(x):
	tmp = sys.stdin.readline()
	return list(tmp[:x])

def err(x):
	print(x)
	exit()
(n, r) = inpl()
pl = []
mi = []
for _ in range(n):
	(a, b) = inpl()
	if b >= 0:
		pl.append((a, b))
	else:
		mi.append([a, b])
pl.sort()
for (a, b) in pl:
	if r < a:
		err('NO')
	r += b
for (i, (a, b)) in enumerate(mi):
	if a + b < 0:
		mi[i][0] = -b
mi.sort(key=lambda x: x[0] + x[1], reverse=True)
for (a, b) in mi:
	if r < a:
		err('NO')
	r += b
print('YES')


(n, r) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))

def sign(x: int):
	if x < 0:
		return -1
	elif x == 0:
		return 0
	else:
		return 1

def comp(x, y):
	if sign(x[1]) == sign(y[1]):
		if x[1] >= 0:
			return x[0] <= y[0]
		else:
			return x[0] + x[1] >= y[0] + y[1]
	else:
		return sign(x[1]) > sign(y[1])
for i in range(n):
	for j in range(i + 1, n):
		if not comp(a[i], a[j]):
			(a[i], a[j]) = (a[j], a[i])
bo = True
for i in range(n):
	if a[i][0] > r:
		bo = False
		break
	r += a[i][1]
	if r < 0:
		bo = False
		break
if bo:
	print('YES')
else:
	print('NO')