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):
x = int(input())
tuple_works = [0 for i in range(x)]
for i in range(x):
    a = input().split()
    tuple_works[i] = (int(a[1]), int(a[0]))
tuple_works=sorted(tuple_works)
time = 0
is_over = False
for i in range(len(tuple_works)):
    time += tuple_works[i][1]
    if time > tuple_works[i][0]:
        print("No")
        is_over = True
        break
if not is_over:
    print("Yes")

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

a = [0]*N
b = [0]*N

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

ab = list(zip(a,b))
quickwork = sorted(ab, key=lambda x: x[1])

t = 0
for i in range(N):
        t += quickwork[i][0]
        if t > quickwork[i][1]:
                print("No")
                break
        
        if i == N-1:
                print("Yes")

Solution (Python):
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
b=sorted(a,key=lambda x:x[1])
time=0
ans=0
for i in range(n):
    time+=b[i][0]
    if time<=b[i][1]:
        continue
    else:
        ans+=1
        print('No')
        break
if ans==0:
    print('Yes')

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

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

works = sorted(works, key=lambda x: x[1], reverse=False)

flag = TabError
spend_time = 0
for i in range(len(works)):
    spend_time += works[i][0]
    if spend_time > works[i][1]:
        flag = False
        break

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

Solution (Python):
n= int(input())
w=[[int(i) for i in input().split()] for j in range(n)]
w.sort(key=lambda x: x[1])
sum_a = 0
for i in range(n):
    sum_a += w[i][0]
    if sum_a > w[i][1]:
        print("No")
        break
else:
    print("Yes")

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

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

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

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

print('Yes')

Solution (Python):
n = int(input())
tasks = []
for i in range(n):
    tasks.append(tuple(map(int,input().split())))
tasks.sort(key=lambda x:x[1])

can = 1
curtime = 0
for task in tasks:
    curtime += task[0]
    if curtime > task[1]:
        can = 0
        break

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

Solution (Python):
n=int(input())
lst=[]
for i in range(n):
    l=list(map(int, input().split()))
    lst.append(l)
lst=sorted(lst,key=lambda x:x[1])
point=0
is_possible=True
for l in lst:
    point+=l[0]
    if point>l[1]:
        is_possible=False
if is_possible:
    print("Yes")
else:
    print("No")

Solution (Python):
if __name__ == "__main__":
    N=int(input())
    work=[]

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

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

Solution (Python):
N=int(input())
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB,key = lambda x:x[1])
S=0
flag=0
for i in range(N):
    S+=AB[i][0]
    if S> AB[i][1]:
        print("No")
        flag=1
        break
if flag == 0:
    print("Yes")

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

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

result = True
time = 0
for i in range(N):
    time += X[i][0]
    if time > X[i][1]:
        result = False
        break

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

Solution (Python):
a = int(input())
ls = []
for i in range(a):
    b,c = input().split()
    s = [int(b),int(c)]
    ls.append(s)

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

def all(lst):
    cnt = 0
    for i, j in lst:
        cnt += i
        if cnt > j:
            return False
    return True
if all(ls_sorted):
    print("Yes")
else:
    print("No")

Solution (Python):


import numpy as np


def solv(n, a_, b_):
    idxs = np.argsort(b_, kind='mergesort')
    t = 0
    for i in idxs:
        t += a_[i]
        if t > b_[i]:
            return 'No'
    return 'Yes'


if __name__ == '__main__':

    n = int(input())
    a_ = np.empty(n, dtype=np.int32)
    b_ = np.empty(n, dtype=np.int32)

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

    ans = solv(n, a_, b_)

    print(ans)

Solution (Python):
n = int(input())
AB = [[int(i) for i in input().split()] for i in range(n)]
ans = ["Yes", "No"]
flag = 0
current = 0
AB.sort(key=lambda x:x[1])
for i in AB:
  current += i[0]
  if current > i[1]:
    flag = 1
    break
print(ans[flag])

Solution (Python):


import numpy as np


def solv(n, a_, b_):
    idxs = np.argsort(b_, axis=0)
    t = 0
    for i in idxs:
        t += a_[i]
        if t > b_[i]:
            return 'No'
    return 'Yes'


if __name__ == '__main__':

    n = int(input())
    a_ = np.empty(n, dtype=np.int32)
    b_ = np.empty(n, dtype=np.int32)

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

    ans = solv(n, a_, b_)

    print(ans)

Solution (Python):
N = int(input())
A = [None for _ in range(N)]
B = [None for _ in range(N)]
endflg = [0 for _ in range(N)]
for i in range(N):
  A[i],B[i] = map(int,input().split())
time = 0
 
z = zip(B,A)
s = sorted(z)
for i in range(N):
  if time + s[i][1] <= s[i][0]:
    time = time +  s[i][1]
    endflg[i] = 1
  else :
    break
    
if endflg == [1 for _ in range(N)]:
  print("Yes")
else:
  print("No")

Solution (Python):
from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = (tuple(map(int, input().split())) for _ in range(n))
a = sorted(a, key=itemgetter(1))
c, d = (map(itemgetter(i), a) for i in (0, 1))
print('YNeos'[any(x > y for x, y in zip(accumulate(c), d))::2])

Solution (Python):
n=int(input())
abs=[list(map(int,input().split()))for i in range(n)]
for i in range(n):
    abs[i].reverse()
abs.sort()
cnt=0
for i in range(n):
    cnt += abs[i][1]
    if cnt > abs[i][0]:
        print('No')
        exit()
print('Yes')

Solution (Python):
import sys
from operator import itemgetter
sysinput = sys.stdin.readline

N = int(sysinput())
A = []


for i  in range(N):
  A.append(list(map(int, sysinput().split())))

A.sort(key=itemgetter(1))

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

Solution (Python):
len = int(input())
arr = []
for i in range(len):
    arr.append(list(map(int, input().split())))
arr.sort(key=lambda x: x[1])
work = 0
schedule = 0
STATUS = "Yes"
for j in arr:
  work += j[0]
  schedule = j[1]
  if work > schedule:
    STATUS = "No"
    break
print(STATUS)

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

b=[]
time=0
out=0

for j in range(0,N):
  b=data[j]
  time=time+b[0]
  
  if time>b[1]:
    out=out+1
    
    
if out>0:
  print("No")
  
else:
  print("Yes")

Solution (Python):
N = int(input())
p = [[0,0]]*N
for i in range(N):
  p[i] = input().split()
  p[i] = list(map(int,p[i]))
p = sorted(p,key = lambda p:p[1])
s = [0]*N
s[0] = p[0][0]
for i in range(N-1):
  s[i+1] = s[i] + p[i+1][0]
k = 0
for i in range(N):
  if s[i] <= p[i][1]:
    k = k + 1
  else:
    print('No')
    break
if k == N:
  print('Yes')

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    aa = sorted([LI() for _ in range(n)], key=lambda x: x[1])
    t = 0
    for a,b in aa:
        t += a
        if t > b:
            return 'No'

    return 'Yes'


print(main())

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

C = list(zip(B,A))
C.sort()
B,A = list(zip(*C))
B = list(B)
A = list(A)

flag = True
time = 0
for i in range(N):
    time += A[i]
    if time > B[i]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

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

t=0
for a,b in ab:
    t+=a
    if b<t:
        print('No')
        exit()
print('Yes')

Solution (Python):
n=int(input())
m=[]
for _ in range(n):
  m+=[list(map(int,input().split()))]
m.sort(key=lambda x:x[1])
t=0
ans=1
for i in range(n):
  t+=m[i][0]
  if t>m[i][1]:
    ans=0
    break
print("YNeos"[1-ans::2])

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

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

time = 0
for i in range(len(task)):
    time += task[i][0]

    if time > task[i][1]:
        print("No")
        exit()

print("Yes")

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

work_total_time = 0
judge = True

for work in work_stack:
    work_time, dead_line = work
    work_total_time += work_time
    
    if work_total_time > dead_line:
        judge = False
        break

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

Solution (Python):
import numpy as np
n = int(input())
a = []
b = []
for i in range(n):
    ai, bi =map(int, input().split())
    a.append(ai)
    b.append(bi)
a = np.array(a)
b = np.array(b)
i = np.argsort(b)
print('Yes') if (np.cumsum(a[i]) <= b[i]).all() else print('No')

Solution (Python):
N = int(input())
lst = []
for n in range(N):
  lst.append(tuple(map(int, input().split())))
lst = sorted(lst, key=lambda x: x[1])
cnt = 0
flag = True
for l in lst:
  cnt += l[0]
  if cnt > l[1]:
    flag = False
print("Yes" if flag else "No")

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

Solution (Python):
N=int(input())
task=[]
for _ in range(N):
    task.append([int(i) for i in input().split()])

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

spent_time1=0
ans='Yes'

for i in range(N):
    spent_time1+=task[i][0]
    deadline1=task[i][1]
    if deadline1<spent_time1:
        ans='No'
        break

print(ans)

Solution (Python):
N=int(input())
task=[]
for _ in range(N):
    task.append([int(i) for i in input().split()])

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

spent_time1=0
spent_time2=0
for i in range(N):
    spent_time2+=task[i][0]
ans='Yes'

for i in range(N):
    spent_time1+=task[i][0]
    deadline1=task[i][1]
    if i!=0:
        spent_time2-=task[N-i][0]
    deadline2=task[N-1-i][1]
    if deadline1<spent_time1:
        ans='No'
        break
    elif deadline2<spent_time2:
        ans='No'
        break
    

print(ans)

Solution (Python):


import sys
import copy

sys.setrecursionlimit(1000000)






N = int(input())

AB = []

for i in range(N):
    AB.append(list(map(int, input().split())))

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


sumV = 0

for i in range(N):
    sumV += AB[i][0]
    if sumV > AB[i][1]:
        print("No")
        exit()

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

time = 0

for A, B in AB:
    if time + A <= B:
        time += A
    else:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
N = int(input())
C=dict()
for i in range(N):
 A,B = [int(j) for j in input().split()]
 if not B in C:
   C[B] = []
 C[B] += [A]
C = sorted(C.items(), key=lambda C:C[0])
s=0
for k,v in C:
    s+=sum(v)
    if k<s:
        print('No')
        exit()
print('Yes')

Solution (Python):
N = int (input())
work = []
work_time = 0
flag = 0

for i in range(N):
    work.append(list(map(int , input().split())))

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






for i in range(N):
    work_time += work[i][0]
    if work_time > work[i][1]:
        flag = 1
        break

if flag == 1:
    print('No')
else:
    print('Yes')

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

work.sort(key=lambda x:(x[1],x[0]))
t=0
ans='Yes'
for i in range(N):
    t+=work[i][0]
    if t>work[i][1]:
        ans='No'
        break
print(ans)

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

for i in AB:
    time += i[0]
    if time > i[1]:
        flag = False
        break

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

Solution (Python):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n = II()
ab = sorted([LI() for _ in range(n)], key=lambda x: x[1])
s = 0
for i in ab:
    s += i[0]
    if s > i[1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
from operator import itemgetter
import sys
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
sum = 0

sort_by_b = sorted(ab, key=itemgetter(1))
for i in range(n):
  sum += sort_by_b[i][0]
  if sum > sort_by_b[i][1]:
    print("No")
    sys.exit(0)
print("Yes")

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

timestamp = 0
for A, B in tasks:
    timestamp += A
    if B < timestamp:
        print('No')
        exit(0)
print('Yes')

Solution (Python):
if __name__ == "__main__":
    N=int(input())
    work=[]

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

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

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

Solution (Python):
n=int(input())
ab=[]
for i in range(n):
	x,y=map(int,input().split())
	ab.append([x,y])
ab=sorted(ab,key=lambda z:z[1])

a,b,f=0,0,0
for i in range(n):
	a+=ab[i][0]
	b=max(b,ab[i][1])
	if b<a:
		f=1

if f:
	print('No')
else:
	print('Yes')

Solution (Python):
s=sorted([list(map(int,input().split()))for i in range(int(input()))],key=lambda x:x[1])
d=0
for i in s:
    if d+i[0]>i[1]:
        print("No")
        break
    else:
        d+=i[0]
else:
    print("Yes")

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

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

time = 0

for task in tasks:
    time += task[0]
    if time > task[1]:
        ans = "No"
        break
else:
    ans = "Yes"

print(ans)

Solution (Python):
from operator import itemgetter

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

tasks.sort(key=itemgetter(1))

time = 0

for task in tasks:
    time += task[0]
    if time > task[1]:
        ans = "No"
        break
else:
    ans = "Yes"

print(ans)

Solution (Python):


import sys

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

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

jikan = 0
for i, j in AB:
    jikan += i
    if jikan > j:
        print("No")
        sys.exit()
print("Yes")

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

Solution (Python):
from operator import itemgetter
n = int(input())
q = [list(map(int,input().split())) for _ in range(n)]

q.sort(key=itemgetter(1))

w = 0
for i in range(n):
  w += q[i][0]
  if w > q[i][1]:
    print('No')
    exit()
print('Yes')

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

Solution (Python):
n = int(input())
work = []
for _ in range(n):
    a, b = map(int, input().split())
    work.append((a,b))
work.sort(key=lambda x:x[1])
t = 0
for i in range(n):
    tim, exp = work[i]
    t +=tim
    if t > exp:
        print('No')
        break

else:
    print('Yes')

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


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

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

Solution (Python):
from operator import itemgetter

n = int(input())
ab = [tuple(int(x) for x in input().split()) for _ in range(n)]

ab.sort(reverse=True, key=itemgetter(1))

d = ab[0][1]

for a, b in ab:
    d = min(d, b)
    d -= a
    if d < 0:
        print('No')
        exit()

print('Yes')

Solution (Python):
N=int(input())
tasks={}
for i in range(N):
    A,B=[int(i) for i in input().split(" ")]
    tasks[B]=tasks.get(B,0)+A

time=0
tasks=sorted(tasks.items(),key=lambda w:w[0])
for task in tasks:
    time+=task[1]
    if time>task[0]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
from operator import itemgetter
n = int(input())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
data.sort(key = itemgetter(1))
time = 0
for i in range(n):
    time += data[i][0]
    if time > data[i][1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
def solve():
 n = int(input())
 query = []
 for i in range(n):
  a,b = (int(i) for i in input().split())
  query.append((a,b))
 ans = True
 query2 = sorted(query, key=lambda x: x[1])

 time = 0
 for i in range(n):
    a,b = query2[i]
    time += a
    if time >b:
      ans = False
 if ans:
  print("Yes")
 else:
  print("No")
solve()

Solution (Python):
N=int(input())
ls2=[]
for i in range(N):
    A,B=map(int,input().split())
    ls1=[A,B]
    ls2.append(ls1)
ls2.sort(key=lambda x:x[1])
t=0
for i in range(N):
    t=t+ls2[i][0]
    if t>ls2[i][1]:
        print('No')
        break
    elif i==N-1:
        print('Yes')

Solution (Python):
from functools import reduce


N = int(input())
A, B = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)


ans, _ = reduce(
    lambda acc, t:
        (
            'Yes' if acc[0] == 'Yes' and acc[1] + t[0] <= t[1] else
            'No',
            acc[1] + t[0]
        ),
    sorted(zip(A, B), key=lambda t: t[1]),
    ('Yes', 0)
)


print(ans)

Solution (Python):
from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = sorted((tuple(map(int, input().split())) for _ in range(n)),
           key=itemgetter(1))
c, d = (map(itemgetter(i), a) for i in (0, 1))
print('YNeos'[any(x > y for x, y in zip(accumulate(c), d))::2])

Solution (Python):
from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = sorted(tuple(map(int, reversed(input().split()))) for _ in range(n))
c, d = (map(itemgetter(i), a) for i in (0, 1))
print('YNeos'[any(x < y for x, y in zip(c, accumulate(d)))::2])

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

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

now = 0
for ab in AB:
    a, b = ab
    if now + a <= b:
        now += a
        continue
    else:
        print('No')
        exit()
print('Yes')

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

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

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

t = 0
flag = True
for i in ablist:
    t += i[0]
    if t > i[1]:
        flag = False

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

Solution (Python):
from operator import itemgetter
N = int(input())
AB = [[int(_) for _ in input().split()] for _ in range(N)]
AB.sort(key = itemgetter(1))

time = 0
for a, b in AB:
    time += a
    if time > b:
        print("No")
        exit()

print("Yes")

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




def merge(la, lb, key):
  na = len(la)
  nb = len(lb)
  ans = [None] * (na+nb)
  ia = 0
  ib = 0
  
  while ia<na and ib<nb:
    if key(la[ia]) < key(lb[ib]):
      ans[ia+ib] = la[ia]
      ia += 1
    else:
      ans[ia+ib] = lb[ib]
      ib += 1
      
  if ia<len(la):
    ans[ia+ib:] = la[ia:]
  if ib<len(lb):
    ans[ia+ib:] = lb[ib:]
  return ans
    
def mergeSort(x, key):
    l = len(x)
    if l <= 1:
        return x
    d = l // 2 
    left = mergeSort(x[:d], key)
    right = mergeSort(x[d:], key)
    return merge(left,right, key)

AB = mergeSort(AB, key=lambda x:x[1])

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

print(ans)

Solution (Python):
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
A = [a for a,b in AB]
B = [b for a,b in AB]
C = list(range(N))

def val(x):
  return B[x]

def merge(la, lb):
  na = len(la)
  nb = len(lb)
  ans = [None] * (na+nb)
  ia = 0
  ib = 0
  
  while ia<na and ib<nb:
    if val(la[ia]) < val(lb[ib]):
      ans[ia+ib] = la[ia]
      ia += 1
    else:
      ans[ia+ib] = lb[ib]
      ib += 1
      
  if ia<len(la):
    ans[ia+ib:] = la[ia:]
  if ib<len(lb):
    ans[ia+ib:] = lb[ib:]
  return ans
    
def mergeSort(x):
    l = len(x)
    if l <= 1:
        return x
    d = l // 2 
    left = mergeSort(x[:d])
    right = mergeSort(x[d:])
    return merge(left,right)

C = mergeSort(C)

ans = "Yes"
t = 0
for i in range(N):
    t += A[C[i]]
    if t > B[C[i]]:
        ans = "No"

print(ans)

Solution (Python):

import re
import bisect
from datetime import datetime as dt
import bisect
import math
from operator import itemgetter

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a * b / gcd(a, b)

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)


if __name__ == '__main__':
    N = int(input())
    arr = [None] * N
    for i in range(N):
        arr[i] = list(map(int, input().split()))
    a = sorted(arr, key=lambda x: (x[1], x[0],))
    
    sum = 0
    for b in a:
        sum += b[0]
        if sum > b[1]:
            print('No')
            exit()
    print('Yes')

Solution (Python):
from collections import deque

N = int(input())

q = deque()

for i in range(N):
    A, B = map(int, input().split())
    q.append((B, A))

work = sorted(q)

A_sum = 0
for w in work:
    A_sum += w[1]

    if A_sum > w[0]:
        print("No")
        exit(0)

print("Yes")

Solution (Python):
from collections import deque

N = int(input())

q = deque()

for i in range(N):
    A, B = map(int, input().split())
    q.append((B, A))

work = sorted(q)

A_sum = 0
for w in work:
    A_sum += w[1]

    if A_sum > w[0]:
        print("No")
        exit(0)

print("Yes")

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

Solution (Python):
import numpy as np
 
n = int(input())
 
l = [list(map(int,input().split())) for _ in range(n)]

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):
import sys
input = sys.stdin.readline

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

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

time = 0

for i,j in li:
    time += i
    if time > j:
        print('No')
        exit()

print('Yes')

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

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

time = 0

for i,j in li:
    time += i
    if time > j:
        print('No')
        exit()

print('Yes')

Solution (Python):
def main():
    n = int(input())
    
    nums = [tuple(map(int,input().split())) for _ in range(n)] 
    nums = sorted(nums, key=lambda x: x[1])
    ans = 'Yes'
    
    _time = 0
    for i in nums:
        _time += i[0]
        if _time > i[1]:
            ans = 'No'
            
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
import operator


def input():
    return sys.stdin.readline()[:-1]


def main():
    n = int(input())
    m = [list(map(int, input().split())) for i in range(n)]
    m.sort(key=operator.itemgetter(1))
    sumTime = 0
    for i in m:
        sumTime += i[0]
        if sumTime > i[1]:
            print("No")
            exit()
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
import itertools

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

def output_list(v):
    print(' '.join(str(x) for x in v))

def main():
    n = int(input())
    p = []
    for i in range(n):
        a, b = input_ints()
        p.append((b, a))
    p.sort()
    t = 0
    for i in range(n):
        if t > p[i][0] - p[i][1]:
            print('No')
            return
        t += p[i][1]
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=[LI() for _ in range(n)]

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

  t=0
  for x in l:
    a,b=x
    t+=a
    if t>b:
      return 'No'

  return 'Yes'

print(main())

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

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


time = 0
for a, b in AB:
    time += a
    
    if b < time:
        print("No")
        exit()
print("Yes")

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

Solution (Python):
N = int(input() )
C = []
for i in range(N):
  A, B = map(int, input().split() )
  C.append([A, B])
C.sort(key=lambda s:s[1] )
 
judge = "Yes"
time = 0
for i in range(N):
  time += C[i][0]
  if time > C[i][1]:
    judge = "No"
    break
print(judge)

Solution (Python):

import sys
input = sys.stdin.readline


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

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

c = 0
for v in ab:
        c += v[0]
        if c>v[1]:
                print("No")
                break
else:
        print("Yes")

Solution (Python):
import sys
from operator import itemgetter
input = sys.stdin.readline
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))
a = 0
flag = 0
for _ in range(n):
  a += l[_][0]
  if a > l[_][1]:
    print('No')
    flag = 1
    break
if flag == 0:
  print('Yes')

Solution (Python):
import sys
from operator import itemgetter
input = sys.stdin.readline
n = int(input())
l = [tuple(map(int,input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))
a = 0
flag = 0
for _ in range(n):
  a += l[_][0]
  if a > l[_][1]:
    print('No')
    flag = 1
    break
if flag == 0:
  print('Yes')

Solution (Python):
import sys
from operator import itemgetter
input = sys.stdin.readline
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]
l.sort(key=itemgetter(1))
a = 0
flag = 0
for _ in range(n):
  a += l[_][0]
  if a > l[_][1]:
    print('No')
    flag = 1
    break
if flag == 0:
  print('Yes')