Problem:
 Score: 400 points    Problem Statement  Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.  Let the current time be time 0 . Kizahashi has N jobs numbered 1 to N .  It takes A_i units of time for Kizahashi to complete Job i . The deadline for Job i is time B_i , and he must complete the job before or at this time.  Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.  Can Kizahashi complete all the jobs in time? If he can, print Yes ; if he cannot, print No .      Constraints   All values in input are integers.  1 \leq N \leq 2 \times 10^5  1 \leq A_i, B_i \leq 10^9 (1 \leq i \leq N)         Input  Input is given from Standard Input in the following format:  N  A_1  B_1  .  .  .  A_N  B_N       Output  If Kizahashi can complete all the jobs in time, print Yes ; if he cannot, print No .        Sample Input 1 5
2 4
1 9
1 8
4 9
3 12      Sample Output 1 Yes  He can complete all the jobs in time by, for example, doing them in the following order:   Do Job 2 from time 0 to 1 .  Do Job 1 from time 1 to 3 .  Do Job 4 from time 3 to 7 .  Do Job 3 from time 7 to 8 .  Do Job 5 from time 8 to 11 .   Note that it is fine to complete Job 3 exactly at the deadline, time 8 .       Sample Input 2 3
334 1000
334 1000
334 1000      Sample Output 2 No  He cannot complete all the jobs in time, no matter what order he does them in.       Sample Input 3 30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720      Sample Output 3 Yes

Solution (Python):
from collections import namedtuple

Task = namedtuple('Task', ('a', 'b'))

def main():
    n = int(input())
    tasks = []

    for _ in range(n):
        a, b = map(int, input().split())
        tasks.append(Task(a, b))

    if solve(tasks):
        print('Yes')
    else:
        print('No')

def solve(tasks):
    t = 0
    for task in sorted(tasks, key=lambda t: t.b):
        t += task.a
        if t > task.b:
            return False
    
    return True


main()

Solution (Python):
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
sa = 0
check = 1
for a,b in ab:
    sa += a
    if sa > b:
        check = 0
        break
print('Yes' if check else 'No')

Solution (Python):
import sys
N = int(input())
A = [list(map(int,input().split())) for x in range(N)]

A_ = sorted(A,key=lambda x: x[1])
Sum = 0
for x in A_:
    Sum += x[0]
    if Sum > x[1]:
        print("No")
        sys.exit()
else:
    print("Yes")

Solution (Python):
n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]
l.sort(key=lambda x:x[1])

s = 0
ind = len(l)
for i in range(len(l)):
    s += l[i][0]
    if (s > l[i][1]):
        ind = i
        break
 
if (ind == len(l)):
    print('Yes')
else:
    print('No')

Solution (Python):
N = int(input())

ts = [tuple(map(int, input().split())) for _ in range(N)]
ts.sort(key=lambda t: t[1])

T = 0
for a, b in ts:
  T+=a
  if T>b:
    print('No')
    exit(0)

print('Yes')

Solution (Python):
N = int(input())

AB = []
for _ in range(N):
    ab = tuple(map(int, input().split()))
    AB.append((ab[1], ab[0]))
AB = sorted(AB)

t = 0
result = "Yes"
for ab in AB:
    t = t + ab[1]
    if t > ab[0]:
        result = 'No'
        break

print(result)

Solution (Python):
N=int(input())
T=[list(map(int,input().split())) for _ in range(N)]

T.sort(key=lambda x:x[0])
T.sort(key=lambda x:x[1])

sum=0
for i in range(N):
  sum+=T[i][0]
  if sum>T[i][1]:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
N =int(input())
A = []
for i in range(N):
    a,b = map(int, input().split())
    A.append([a,b])
A.sort(key=lambda x:x[1])
tmp = 0
for t,up in A:
    if tmp + t > up:
        print('No')
        break
    tmp += t
else:
    print('Yes')

Solution (Python):
N = int(input())
T = []

for _ in range(N):
	a, b = map(int, input().split(' '))
	T.append((a, b))

T = sorted(T, key=lambda t: t[1])

s = 0
ok = True

for (t, d) in T:
	s += t
	if s > d:
		ok = False
		break

print('Yes' if ok else 'No')

Solution (Python):
N = int(input())
AB = []
for n in range(N):
  AB.append([int(ab) for ab in input().split()])
AB.sort(key=lambda x:(x[1], x[0]))

T = 0
for n in range(N):
  T += AB[n][0]
  T_limit = AB[n][1]
  if T > T_limit:
    print("No")
    break
else:
  print("Yes")

Solution (Python):



def main():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    mod_ab = sorted(ab, key=lambda x: (x[1], x[0]))
    time = 0
    b_max = mod_ab[-1][1]

    for ai, bi in mod_ab:
        time += ai

        if time > b_max or time > bi:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
N = input()
AB = []
NGflag = 0
for i in range(N):
	a,b = map(int, raw_input().split())
	AB.append((a,b))
ABsort =sorted(AB,key = lambda x:x[1])
now = 0
for item in ABsort:
	now += item[0]
	if now > item[1]:
		NGflag = 1
		break
if NGflag == 0:
	print("Yes")
else:
	print("No")

Solution (Python):

import numpy as np
def acinput():
    return list(map(int, input().split(" ")))

N=int(input())

S=[]
a=[]
for i in range(N):
    tmp=acinput()
    S.append(tmp)


S=sorted(S,key=lambda x:x[1])
a=[]
b=[]
for ss in S:
    a.append(ss[0])
    b.append(ss[1])
acs=np.cumsum(a)

res="Yes"
for i in range(N):
    if acs[i]>b[i]:
        res="No"
        break

print(res)

Solution (Python):
n = int(input())

ab = []

for i in range(n):
    a, b = map(int, input().split())
    a = b - a
    ab.append([a, b])

ab.sort(key=lambda x: (x[1], x[0]))

flag = True
time = 0
for i in range(n):
    a, b = ab[i]
    time += b - a
    if time > b:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
tmp = zip(B, A)
B, A = zip(*sorted(tmp))

total = 0
flag = False
for b, a in zip(B, A):
    total += a
    if total > b:
        flag = True
        break
if flag:
    print("No")
else:
    print("Yes")

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key=lambda x:x[1])
s=0
ans='Yes'
for i in range(N):
    s += AB[i][0]
    if s > AB[i][1]:
        ans='No'
print(ans)

Solution (Python):


import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
AB=[]
for i in range(N):
    a,b=MAP()
    AB.append((a, b))

AB.sort(key=itemgetter(1))
time=0
for i in range(N):
    a,b=AB[i]
    time+=a
    if b<time:
        No()
        exit()
Yes()

Solution (Python):
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
T.sort(key=lambda x:x[1])
time=0
err=0
for i in range(N):
    time=time+T[i][0]
    if time>T[i][1]:
        err=1
        break
if time<=T[N-1][1] and err==0:
    print("Yes")
else:
    print("No")

Solution (Python):

import sys
from operator import itemgetter

n = int(input())
o = []
for i in range(n):
    o.append(list(map(int, input().split())))
o.sort(key=itemgetter(1))

t = 0
for j in range(n):
    t += o[j][0]
    if t > o[j][1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
n=int(input())
lst=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x : x[1])
tmptime=0
hp=0
flag=True
for i in range(n):
    hp+=lst[i][1]-tmptime
    tmptime=lst[i][1]
    hp-=lst[i][0]
    if hp<0:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
import math

n = int(input())

table = [[int(i) for i in input().split()] for j in range(n)]






table2 = sorted(table, key=lambda x:(x[1]))
sum = 0
flag = 0


for i in range(n) :
    sum += table2[i][0]
    if (sum > table2[i][1]) :
        flag = 1


if (flag == 0) :
    print("Yes")
else :
    print("No")

Solution (Python):
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N = int(input())
    jobs = []
    for i in range(N):
        time_consume, deadline = map(int, input().split())
        jobs.append([deadline, time_consume])
    jobs = sorted(jobs)
    
    time_ = 0
    for i in range(N):
        time_ += jobs[i][1]
        if (time_ <= jobs[i][0]):
            
            pass
        else:
            print("No")
            break
    else:
        print("Yes")



if __name__ == '__main__':
    main()

Solution (Python):



N = int(input())

l = []
for i in range(N):
    A,B= map(int,input().split())
    l.append([B,A])
l.sort()

ruiseki = [0]*(N+1)
for i in range(N):
    ruiseki[i+1] = ruiseki[i]+l[i][1]
for i in range(N):
    if l[i][0] < ruiseki[i+1]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):







import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations 
from math import factorial
def factorize(n):
    """return the factors of the Arg and count of each factor
    
    Args:
        n (long): number to be resolved into factors
    
    Returns:
        list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
    """
    fct = []  
    b, e = 2, 0  
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def combinations_count(n, r):
    
    
    
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter 
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
from copy import deepcopy, copy 
from operator import itemgetter 


from functools import reduce
from fractions import gcd 
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)



INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) 
def modinv(a, p = MOD):
    
    
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    
    
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))




    
    

    
    
    
    
    

    
    


r = lambda: sys.stdin.readline().strip() 
R = lambda: list(map(int, r().split())) 
R_t = lambda: tuple(map(int, r().split()))
Rmap = lambda: map(int, r().split())


N = int(r())
AB = [R_t() for _ in range(N)]
ABC = [(a,b,b-a) for a,b in AB]
ABC.sort(key=itemgetter(1))
time = 0
for a, b, c in ABC:
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")

Solution (Python):

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

from operator import itemgetter


N = int(input())


AB = [(0, 0, 0)]*N
for n in range(N):
    a, b = list(map(int, input().split()))
    AB[n] = (a, b, b-a) 
AB = tuple(sorted(AB, key = itemgetter(1)))

    
def main():
    tot = 0
    for i, ab in enumerate(AB):
        if tot <= ab[2]:
            tot+=ab[0]
        else:
            return print("No")
        
    print("Yes")
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

l = [list(map(int, input().split())) for _ in range(N)]
l = sorted(l, key=lambda x:x[1])

t = 0
for A, B in l:
    t += A
    if t > B:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
import numpy as np
N =int(input())
A =[]
B =[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
index = np.argsort(B)
time = 0
f = 0
for i in index:
    time += A[i]
    if time>B[i]:
        f = 1
        break
if f == 1:
    print('No')
else:
    print('Yes')

Solution (Python):
from collections import defaultdict

d = defaultdict(lambda: 0)
N = int(input())
for _ in range(N):
    a, b = map(int, input().split())
    d[b] += a
d_keys = list(d.keys())
d_keys.sort()
tmp_time = 0
flag = True
for i in range(len(d_keys)):
    tmp_time += d[d_keys[i]]
    if tmp_time > d_keys[i]:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
tasks = []
for i in range(n):
    a,b = map(int, input().split())
    tasks.append((a,b))

tasks.sort(key=lambda x:x[1])


cur = 0
c = True
for i in range(n):
    cur += tasks[i][0]
    if cur > tasks[i][1]:
        c = False

print("Yes" if c else "No")

Solution (Python):
n = int(input())
w = {}
for i in range(n):
  a, b = map(int,input().split())
  if b in w:
    w[b] += a
  else:
    w[b] = a
sum = 0
w = sorted(w.items(), key=lambda x:x[0])

for i in range(len(w)):
  k = w[i][0]
  v = w[i][1]
  sum += v
  if sum > k:
    print("No")
    break
else:
  print("Yes")

Solution (Python):
def code_for_D(test=None):

    N = int(input())

    works = [list(map(int, input().split())) for _ in range(N)]
    works = sorted(works, key=lambda x: x[1])

    time_now = 0
    answer = 'Yes'

    for work in works:
        time_now += work[0]
        time_by = work[1]

        if time_now > time_by:
            answer = 'No'

    print(answer)


def main():
    code_for_D()


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

allList = []
for _ in range(N):
    allList.append(list(map(int,input().split())))
allList.sort(key=lambda x: x[1])

s = "Yes"
time=0
for t, shime in allList:
    time += t
    if time > shime:
        s = "No"
print(s)

Solution (Python):
N=int(input())
AB=[list(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[1])

able = True
sum = 0

for i in range(N):
  sum += AB[i][0]
  if (sum > AB[i][1]):
    able = False
    break

print("Yes" if able else "No")

Solution (Python):
from operator import itemgetter

n = int(input())

a = []
b = []
for i in range(n):
  _a, _b = map(int, input().split())
  a.append(_a)
  b.append(_b)

c = sorted(zip(a, b), key=itemgetter(1))
a, b = zip(*c)
a = list(a)
b = list(b)

for i in range(1, n):
  a[i] += a[i-1]

flag = True

for i in range(n):
  if a[i] > b[i]:
    flag = False
    break

print("Yes" if flag else "No")

Solution (Python):
def solve(J):
    t = 0
    J.sort(key=lambda x: x[0])
    J.sort(key=lambda x: x[1])
    for i in range(len(J)):
        t += J[i][0]
        if t > J[i][1]:
            return False
    return True


N = int(input())
Job = [list(map(int, input().split())) for _ in range(N)]
print("Yes") if solve(Job) else print("No")

Solution (Python):
N = int(input())
tasks = []
for _ in range(N):
    A, B = map(int, input().split())
    tasks.append([A, B])
tasks.sort(key=lambda x:x[1])

nums = [0]
for i, t in enumerate(tasks):
    nums.append(nums[i]+t[0])
    if nums[i+1] > t[1]:
        print('No')
        quit()
print('Yes')

Solution (Python):
n = int(input())
wl = []
for i in range(n):
    wl.append(list(map(int,input().split())))
wl.sort(key = lambda x: x[1])
wls = 0
f = 0
for i in range(n):
    wls = wls+wl[i][0]
    if(wls > wl[i][1]): f += 1
if(f == 0):
    print("Yes")
else: print("No")

Solution (Python):
import sys

n = int(input())
task = []
for i in range(n):
    temp = list(map(int,input().split()))
    task.append(temp)
    
task = sorted(task, key=lambda x:(x[1],x[0]))
temp_time = 0
for i in range(n):
    if temp_time+task[i][0] <= task[i][1]:
        temp_time += task[i][0]
    else:
        print("No")
        sys.exit()
        
print("Yes")

Solution (Python):
N = int(input())

ABs = []

for i in range(N):
    a,b = map(int,input().split())
    ABs.append((a,b))

sorted_ABs = sorted(ABs,key=lambda ab: ab[1])

times = 0
before_line = 0
for ab in sorted_ABs:
    times += (ab[1] - before_line)
    before_line = ab[1]
    tmp = times - ab[0]
    if tmp < 0:
        print("No")
        exit()

    times -= ab[0]

print("Yes")

Solution (Python):


n = int(input())

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


abn.sort()
abn.sort(key = lambda x:x[1])




ts = 0 
enable = True
for abi in abn:
    a, b = abi

    if not ts + a <= b:
        enable = False
        break
    else:
        ts += a

print('Yes' if enable else 'No')

Solution (Python):
n = int(input())
x = []
for i in range(n):
    a,b = map(int,input().split())
    x.append([a,b])
x = sorted(x,key=lambda x:(x[1],x[0]))
t = 0
for i in range(n):
    t+=x[i][0]
    if t>x[i][1]:
        print("No")
        exit()
else:
    print("Yes")

Solution (Python):
N = int(input())
work = []
for i in range(N):
    work.append(list(map(int, input().split())))
work.sort(key=lambda x:x[0])
work.sort(key=lambda x:x[1])

time = 0

for A, B in work:
    time += A
    if time > B:
        print("No")
        break
        
else:
    print("Yes")

Solution (Python):
import numpy as np

n = int(input())

l = []

for i in range(n):
    tmp = list(map(int,input().split()))
    l.append(tmp)

l = np.array(l)
l = l[np.argsort(l[:,1],axis=0)]
ans = l[:,1]-np.cumsum(l[:,0])
ans = np.where(ans<0)[0]

print("Yes" if ans.shape[0]==0 else "No")

Solution (Python):
from operator import itemgetter
n = int(input())
ab = sorted([[int(i) for i in input().split()] for i in range(n)],key=itemgetter(1))
sum = 0
for a,b in ab:
    sum += a
    if sum > b:
        print('No')
        exit()
print('Yes')

Solution (Python):
import sys

N = int(input())

jobs = []

for i in range(N):
    A, B = list(map(int, input().split()))
    jobs.append([B, A])

jobs = sorted(jobs)

time = 0

for job in jobs:
    time += job[1]
    if time > job[0]:
        print('No')
        sys.exit(0)

print('Yes')

Solution (Python):
N = int(input())
tasks = []
for i in range(0, N):
  t = list(map(int, input().split(' ')))
  tasks.append(t)
tasks = sorted(tasks, key=lambda x: x[1])
sum_time = 0
is_done = True
for t in tasks:
  sum_time += t[0]
  if sum_time > t[1]:
    is_done = False
    break
if is_done:
  print('Yes')
else:
  print('No')

Solution (Python):

from operator import itemgetter
import sys
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))

sate = [0]
flag = True

for i in range(n):
    sate.append(sate[i] + l[i][0])
    if (sate[i + 1] > l[i][1]):
        flag = False
        print("No")
        exit()
print("Yes")

Solution (Python):
N = int(input())

AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([b, a])   
AB.sort()

ans = "Yes"
time = 0
for b, a in AB:
    time += a
    if time > b:
        ans = "No"
        break

print(ans)

Solution (Python):
n = int(input())
a,b = [],[]
ideal = 0
real = 0
for i in range(n):
    a1,b1 = map(int, input().split())
    a.append(a1)
    b.append([b1,i])

b.sort()
for i in range(n):
    ideal = max(ideal, b[i][0])
    real += a[b[i][1]]
    if real > ideal:
        print("No")
        break
    if i == n-1:
        print("Yes")

Solution (Python):


import math

def main():
    n = int(raw_input())
    cnt = n 
    ps = []
    for i in range(cnt):
        a,b = map(int, raw_input().split())
        ps.append([b,a])
    ps.sort()
    total = None
    chk = True
    now = 0
    for i in ps:
        tmp = i[0] - i[1]
        if total == None:
            if tmp >= 0:
                total = tmp
                now = i[0]
            else:
                chk = False
                print "No"
                break
        else:
            total = total + i[0] - now - i[1]
            now = i[0]
            if total < 0:
                chk = False
                print "No"
                break
    if chk:
        print "Yes"

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N = int(input())
A_B = []
for i in range(N):
	A_B.append(list(map(int,input().split())))
A_B = np.array(A_B)

A_B_sort = A_B[np.argsort(A_B[:,1])]
time = 0
judge = True
for A_B_data in A_B_sort:
	time += A_B_data[0]
	if time > A_B_data[1]:
		judge = False
		break
if judge:
	print("Yes")
else:
	print("No")

Solution (Python):
import sys
input = sys.stdin.readline

from operator import itemgetter

n = int(input())
work = []
for i in range(n):
	a, b = map(int, input().split())
	c = b-a
	work.append([a, b, c]) 
work.sort(key = itemgetter(1))


time = 0
for item in work:
	
	if time <= item[2]:
		time += item[0]
	else:
		print("No")
		exit()
print("Yes")

Solution (Python):
N = int(input())
AB = {}
for i in range(N):
  A,B = map(int,input().split())
  if B in AB.keys():
    AB[B] += A
  else:
    AB[B] = A
time = 0
for b in sorted(AB.keys()):
  time += AB[b]
  if time > b:
    print("No")
    break
else:
  print("Yes")

Solution (Python):
import numpy as np

N = int(input())
A = []
B = []

for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
A = np.array(A)
B = np.array(B)

J = np.argsort(np.array(B))
A = A[J]
B = B[J]

A = np.cumsum(A)

ans = np.min(B - A)

if (ans < 0):
  print('No')
else:
  print('Yes')

Solution (Python):
import sys

N = int(input())
a = [[int(i) for i in input().split()] for i in range(N)]

a_sorted = sorted(a, key=lambda x: x[1])

s = 0
for t in range(N):
  s+=a_sorted[t][0]
  if s > a_sorted[t][1]:
    print("No")
    sys.exit()
print("Yes")

Solution (Python):
n = int(input())

ab = []
for i in range(n):
    ab.append([int(i) for i in input().split()])

ab.sort(key=lambda x: x[1])
time = 0
for i in range(n):
    time += ab[i][0]
    if time > ab[i][1]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):


N = int(input())

AB = [list(map(int, input().split())) + [0] for i in range(N)]

AB.sort(key=lambda x: x[1])

AB[0][2] = AB[0][0]
for i in range(N - 1):
    AB[i + 1][2] = AB[i][2] + AB[i + 1][0]

for i in range(N):
    if AB[i][1] < AB[i][2]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):

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

ab.sort()
s = 0
flg = 0

for i in range(n):
    s += ab[i][1]
    if s>ab[i][0]:
        flg = 1
        break

if flg == 0:
    print("Yes")

else:
    print("No")

Solution (Python):
n = int(input())
list_ = [tuple(map(int, input().split())) for i in range(n)]
list_.sort(key=lambda x: x[1])
time = 0
for a, b in list_:
    time += a
    if time > b:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10


N = int(stdin.readline().rstrip())
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

AB.sort(key=lambda x: (x[1], x[0]))

sum_time = 0

for A, B in AB:
    sum_time += A

    if sum_time > B:
        print("No")
        exit()

print("Yes")

Solution (Python):
import sys

def main():
    n = int(sys.stdin.readline().strip())
    task = [tuple(int(i) for i in sys.stdin.readline().strip().split()) for _ in range(n)]
    task.sort(key=lambda x: x[1])
    time = 0
    for t in task:
        time += t[0]
        if time > t[1]:
            return 'No'
    return 'Yes'

print(main())

Solution (Python):
def main():
     n=int(input())
     task=[list(map(int,input().split())) for i in range(n)]
     task.sort(key=lambda x:x[1])
     now=0
     flag=0
     for task_i in task:
          now+=task_i[0]
          if now>task_i[1]:
               print("No")
               flag=1
               break
     if flag==0:
          print("Yes")
          
     
if __name__=='__main__':
     main()

Solution (Python):
N = int(input())
ABs = [None]*N
for i in range(N):
    ABs[i] = list(map(int, input().split()))

ABs = sorted(ABs, key=lambda x:x[1])

time = 0
answer = "Yes"
for i in range(N):
    A, B = ABs[i]
    time += A
    if time > B:
        answer = "No"
        break

print(answer)

Solution (Python):



N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]


AB.sort(key = lambda x:x[1])
sum_tmp = 0
idx = 0
for i in range(len(AB)):
    sum_tmp += AB[i][0]
    if sum_tmp > AB[i][1]:
        idx = 1
if idx == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
t=0
for a,b in ab:
    t+=a
    if t>b:
        print("No")
        exit()
print("Yes")

Solution (Python):

N = int(input())
ab = [list(map(int,input().split())) for _ in range(N)]

ab.sort(key = lambda x:x[1])

tmp = 0
flag = True
for i in range(N):
    tmp += ab[i][0]
    if tmp > ab[i][1]:
        flag = False
        break
    
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=lambda x: x[1])

flag = True
t = 0
for i in range(len(ab)):
    a, b = ab[i]
    t += a
    if b < t:
        flag = False
        break


print('Yes' if flag else 'No')

Solution (Python):
n = int(input())
ab = []

for i in range(n):
  ab.append(list(map(int, input().split())))

ab.sort(key=lambda x:x[1])

result = 'Yes'
a_sum, b_sum = 0, 0

for i in ab:
  a_sum += i[0]
  
  if a_sum > i[1]:
    result = 'No'
    
print(result)

Solution (Python):
n = int(input())
ab_s = [[int(v) for v in input().split()] for _ in range(n)]

ab_s.sort(key=lambda x:x[1])
c = 0
for i in range(n):
  c += ab_s[i][0]
  if c > ab_s[i][1]:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
N = int(input())
dic = [[0,0] for i in range(N)]
for i in range(N):
    A = input().split(" ")
    dic[i] = A

dic_s = sorted(dic,key=lambda x: int(x[1]))

t = 0
ans = "Yes"
for i in range(N):
    
    t += int(dic_s[i][0])
    if (t > int(dic_s[i][1])):
        ans = "No"
        break

print(ans)

Solution (Python):
n=int(input())
ab=[]
for i in range(n):
	x,y=map(int,input().split())
	ab.append([x,y])
ab.sort(key=lambda x:x[1])
time=0
out=0
for i in range(n):
	time+=ab[i][0]
	if time>ab[i][1]:
		out+=1
if out==0:
	print("Yes")
else:
	print("No")

Solution (Python):
N=int(input())
work=[[0,0]for i in range(N)]
sum=0
ans=0
for x in range(N):
  inp=input().split()
  work[x][0]=int(inp[1])
  work[x][1]=int(inp[0])
work2=sorted(work)
for y in range(N):
  sum+=work2[y][1]
  if sum>work2[y][0]:
    ans=1
    break
if(ans==0):
  print('Yes')
else:
  print('No')

Solution (Python):
N=int(input())
AB = [[int(i) for i in input().split()] for j in range(N)]
ABDeadStart = [[A,B,B-A] for A,B in AB]
MaxShoyou = sum([a for a,b,kaisi in ABDeadStart])
ABDeadStart.sort(key = lambda x:x[2]-MaxShoyou+x[0])
curtime = 0
NO =0
for a,b,ds in ABDeadStart:
    if curtime <= ds:
        curtime += a
    else:
        NO =True
        break
if NO :print("No")
else:print("Yes")

Solution (Python):
from operator import itemgetter

n = int(input())
ab = sorted([list(map(int, input().split())) for i in range(n)], key=itemgetter(1))
t = 0
for i in ab:
    a, b = i
    t += a
    if b < t:
        print("No")
        exit()
print("Yes")

Solution (Python):
N = int(input())

AB = [0]*N
for i in range(N):
    AB[i] = list(map(int, input().split()))

AB.sort(key=lambda x:x[1])
time = 0
for a,b in AB:
    time += a
    if time > b:
        print('No')
        quit()
print('Yes')

Solution (Python):
import numpy as np
N = int(input())
AB =np.zeros((N,2),dtype=np.int32)
for i in range(N):
    AB[i,:]=list(map(int,input().split()))

ABs = AB[np.argsort(AB[:, 1])]

output = "Yes"

T = 0
for i in range(N):
    T += ABs[i,0]
    if T>ABs[i,1]:
        output = "No"

print(output)

Solution (Python):
from sys import stdin
import math


n = int(stdin.readline().rstrip())

m = {}

for i in range(n):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if b in m:
      m[b] += a
    else:
      m[b] = a

mm = sorted(m.items(), key=lambda x:x[0])

ans = "Yes"
sum = 0
for k,v in mm:
  
  sum += v
  if sum > k:
      ans = "No"
      break

print(ans)

Solution (Python):
N = int(input().strip())

AB = [[int(i) for i in input().strip().split()] for _ in range(N)]
AB = sorted(AB, key=lambda a: a[1])

t = 0
for a, b in AB:
  t += a
  if t > b:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
n=int(input())
listat = []
listb = []
for i in range(n):
    a,b=map(int,input().split())
    listat.append(a)
    listb.append(b)

sb = sorted(range(len(listb)), key=lambda k: listb[k])

listb.sort()
lista = []
for i in range(n):
    ii = sb[i]
    lista.append(listat[ii])



time = 0
ans = "Yes"
for i in range(n):
    time+=lista[i]
    if time>listb[i]:
        ans = "No"
        break 
print(ans)

Solution (Python):
n = int(input())
ls = [[int(x) for x in input().split()] for _ in range(n)]

ls = sorted(ls,key=lambda x:x[1])

now=0

for i in range(n):
    now+=ls[i][0]
    if now<=ls[i][1]:
        pass
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
N = int(input())
ABs = [list(map(int, input().split())) for i in range(N)]
ABs = sorted(ABs, key=lambda x:x[1])
total = 0
is_comp = True
for task_i in ABs:
    total += task_i[0]
    
    if total > task_i[1]:
        is_comp = False
        break
if is_comp:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
X = [None]*N
for k in range(N):
	X[k] = tuple(map(int,input().split()))
X.sort(key=lambda q: q[1])
time = 0
late = 0
for x in X:
	time += x[0]
	if time > x[1]:
		late = 1
		break
if late == 1:
	print("No")
else:
	print("Yes")

Solution (Python):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(AB,key=lambda x:x[1])

s = 0
for ab in AB:
    s += ab[0]
    if s > ab[1]:
        print('No')
        break
else:
    print('Yes')