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):
def main(n, a_b):
    a_b.sort(key=lambda a_b: a_b[1])

    t = 0
    for a, b in a_b:
        t += a
        if t > b:
            print('No')
            return

    print('Yes')


if __name__ == "__main__":
    n = int(input())
    a_b = [list(map(int, input().split())) for _ in range(n)]

    main(n, a_b)

Solution (Python):
N = int(input())
ABlist = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
now = 0
for a, b in ABlist:
    now += a
    if now <= b:
        continue
    else:
        print("No")
        break
else:
    print("Yes")

Solution (Python):


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

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


t=0
ans=0
for i in range(N):
    if t+L[i][0]<=L[i][1]:
        ans+=1
        t+=L[i][0]

if ans==N:
    print('Yes')
else:
    print('No')

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

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

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

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

print('Yes')

Solution (Python):
n=int(input())
tasks=[]
for i in range(0,n):
    a,b=map(int,input().split())
    tasks.append((b,a))
tasks.sort()
now=0
fail=0
for i in tasks:
    b=i[0]
    a=i[1]
    now+=a
    if now>b:
        fail=1
if fail:
    print("No")
else:
    print("Yes")

Solution (Python):
N = int(input())
t = 0
ans = "Yes"
tasks = []
for i in range(N):
  tasks.append(list(map(int, input().split())))
tasks.sort(key=lambda task: task[1])
for task in tasks:
  t += task[0]
  if task[1] < t:
    ans = "No"
    break
print(ans)

Solution (Python):
N = int(input())
t = 0
ans = "Yes"
tasks = []
for i in range(N):
  tasks.append(list(map(int, input().split())))
tasks.sort(key=lambda task: task[1])
for task in tasks:
  t += task[0]
  if task[1] < t:
    ans = "No"
    break
print(ans)

Solution (Python):
from heapq import heappush, heappop
N = int(input())
AB = []

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


current = 0

for i in list(range(N)):
  deadline, cost = heappop(AB)

  if current + cost > deadline: 
    print("No")
    exit()
  
  current += cost

print("Yes")

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

Solution (Python):
n=int(input())
AB=[list(map(int,input().split())) for i in range(n)]
AB.sort(key=lambda A:A[1])
flag=0
cnt=0
for i in range(n):
    cnt+=AB[i][0]
    if cnt>AB[i][1]:
        flag=1
print('Yes' if flag==0 else 'No')

Solution (Python):
n = int(input())
tasks = []
for i in range(n):
  a = list(map(int, input().split()))
  tasks.append(a)
tasks.sort(key=lambda x: x[1])
sum = 0
answer = True
for i in range(n):
  sum += tasks[i][0]
  if sum <= tasks[i][1]:
    continue
  else:
    answer = False
    break
if answer:
  print('Yes')
else:
  print('No')

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

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

t = 0

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

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

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
cnt=0
for x,y in A:
    tmp+=x
    if tmp<=y:
        cnt+=1
if cnt==n:
    print("Yes")
else:
    print("No")

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

data = sorted(data, key=lambda d: d[1])

work_time = 0
impossible = False
for a, b in data:
    deadline = b
    work_time += a
    if work_time > b:
        impossible = True
        break

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

Solution (Python):
def main():
    N = int(input())
    tasks = []

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

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

    time = 0
    for task in tasks:
        time += task[0]
        if time > task[1]:
            print("No")
            return 0

    print("Yes")
    return 0

if __name__ == '__main__':
    main()

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

i = 0
ab = []
while i < n:
    a, b = map(int, input().split())
    ab.append((a, b)) 
    i += 1

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

i = 0
ans = 'Yes'
days = 0
while i < n:
    days += ab[i][0]
    if days > ab[i][1]:
        ans = 'No'
        break
    i += 1
print(ans)

Solution (Python):
n = int(input())
ab =[list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda l: l[1])
t = 0
out = 'Yes'
for i in range(n):
  t += ab[i][0]
  if t > ab[i][1]:
    out = 'No'
    break
print(out)

Solution (Python):
def main():
    n = int(input())
    a = [list(map(int, input().split())) for i in range(n)]
    s = sorted(a, key=lambda x:x[1])

    t = 0
    for i in range(n):
        t += s[i][0]
        if t > s[i][1]:
            print('No')
            return
    print('Yes')
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    flag = True
    tascs = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        tmp = [a, b]
        tascs.append(tuple(tmp))
    tascs.sort(key=lambda x: x[1])
    passed_time = 0
    for tasc in tascs:
        passed_time += tasc[0]
        if passed_time > tasc[1]:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a=[]
time=0
ans=True

for i in range(n):
    s,p=map(int,input().split())
    a+=[[s, p] ]
    

import operator as op
a.sort(key = op.itemgetter(1))

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

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

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

due = 0
time = 0
for i in range(n):
    due = ab[i][0]
    time += ab[i][1]
    
    if time > due:
        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()

due = 0
time = 0
for i in range(n):
    due = ab[i][0]
    time += ab[i][1]
    
    if time > due:
        print("No")
        exit()
print("Yes")

Solution (Python):

n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
l=sorted(l,key=lambda x:x[1])
deadline=0
tmp=0
for i in range(n):
    tmp=l[i][1]
    deadline+=l[i][0]
    if tmp<deadline:
        print("No")
        exit()
print("Yes")

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

time=0
flag=True
for i in range(n):
  if Wo[i][0]+time<=Wo[i][1]:
    time+=Wo[i][0]
  else:
    flag=False
    break

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

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(input()) 
def isn(): return input().split() 
def imn(): return map(int, input().split()) 
def iln(): return list(map(int, input().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
def run_length_encode(s):
    count = 1
    code = []
    target = s[0]
    for i in range(1, len(s)):
        if target == s[i]: count += 1
        else:
            code.append((target, count))
            target = s[i]
            count = 1
    code.append((target, count))
    return code

N = iin()
AB = sorted([iln() for _ in range(N)], key=lambda x:x[1])

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
ab = [list(map(int,input().split())) for _ in range(N)]
ab = sorted(ab, key = lambda x:x[1],reverse=False)
deadline = 0 
for i in range(N):
    a = ab[i][0]
    b = ab[i][1]
    deadline += a
    if deadline > b:
        print("No")
        exit()
print("Yes")

Solution (Python):
N=int(input())
BA=[[0,0] for _ in range(N)]

for i in range(N):
    BA[i][1],BA[i][0]=map(int,input().split())
BA.sort()

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

Solution (Python):
n=int(input())
mat=[]
for i in range(n):
	a,b=map(int,input().split())
	mat.append([b,a])
mat.sort()
t=0
f=1
for i in range(n):
	if(t+mat[i][1]<=mat[i][0]):
		t+=mat[i][1]
	else:
		f=0
		break
if(f):
	print("Yes")
else:
	print("No")

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

time = 0
for deadline, task_time in deadlines:
    if time + task_time <= deadline:
        time += task_time
    else:
        time = None
        break
print('Yes' if time is not None else 'No')

Solution (Python):
from fractions import Fraction
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
AB=sorted(AB,key=lambda x:x[1])
time=0
for a,b in AB:
    time+=a
    if time>b:
        print("No")
        exit()
print("Yes")

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

now = 0
ok = 1
for i in range(N):
  now += AB[i][0]
  if now > AB[i][1]:
    ok=0
    break
    
if ok:
  print("Yes")
else:
  print("No")

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

Solution (Python):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        AB = [tuple(map(int, input().split())) for _ in range(N)]

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



if __name__ == '__main__':
    AtCoder().main()

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

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

t = 0

for i in range(N):
    t += work[i][0]
    if t > work[i][1]: 
        print('No')
        exit()
print('Yes')

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

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

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


fa, fb = AB[0][0], AB[0][1]
t = fb - fa
for a, b in AB[1:]:
    if b <= t:
        t = b
    t -= a
    

if t >= 0:
    print('Yes')
else:
    print('No')

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

heapq.heapify(tasks)

ans = "Yes"
time = 0
while len(tasks) > 0 :
    task = heapq.heappop(tasks)
    time += task[1]

    if task[0] < time:
        ans = "No"
        break

print(ans)

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

sum = 0
for i in range(n):
    sum += asort[i][0]
    if sum > asort[i][1]:
        print("No")
        exit()
print("Yes")

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

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

a_list = []
b_list = []
t = []
for i in range(n):
  a, b = map(int, input().split())
  t.append({"time": a, "limit": b})
  a_list.append(a)
  b_list.append(b)
  
s = sorted(t, key=lambda x: x["limit"])

time = 0
for ss in s:
  time += ss['time']
  if time > ss['limit']:
    print('No')
    exit(0)

print('Yes')

Solution (Python):
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
ab = []
for _ in range(n):
    abi = na()
    ab.append(abi)

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

Solution (Python):
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


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


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


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    N = get_input(int)
    AB = []
    for _ in range(N):
        A, B = get_inputs(int)
        AB.append((A, B))
    AB.sort(key=lambda x: x[1])

    cur_time = 0
    for A, B in AB:
        cur_time += A
        if cur_time > B:
            print('No')
            return
    print('Yes')
    return


if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter
N=int(input())
tasks=[list(map(int,input().split())) for _ in range(N)]
tasks.sort(key=itemgetter(1))
t=0
for w,l in tasks:
    if t+w>l:
        print('No')
        exit()
    t+=w
print('Yes')

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


def f():
    time = 0
    for task in tasks:
        time += task[0]
        if time > task[1]:
            return "No"
    
    return "Yes"

print(f())

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

def main():
  n = int(input())
  abs = [tuple(map(int, input().split())) for _ in range(n)]

  pq = []

  for ab in abs:
    a,b = ab[0],ab[1]
    heapq.heappush(pq, tuple([b,a]))

  dl = 0
  tc = 0

  ans = "Yes"

  for i in range(n):
    ba = heapq.heappop(pq)
    dl = ba[0]
    tc += ba[1]
    if dl < tc:
      ans = "No"
      break
  print(ans)
  
if __name__ == "__main__":
  main()

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

def main():
  n = int(input())
  abs = [tuple(map(int, input().split())) for _ in range(n)]

  pq = []

  for ab in abs:
    a,b = ab[0],ab[1]
    heapq.heappush(pq, tuple([b,a]))

  dl = 0
  tc = 0

  ans = "Yes"

  for i in range(n):
    ba = heapq.heappop(pq)
    dl = ba[0]
    tc += ba[1]
    if dl < tc:
      ans = "No"
      break
  print(ans)
  
if __name__ == "__main__":
  main()

Solution (Python):
import heapq

def main():
  n = int(input())
  abs = [tuple(map(int, input().split())) for _ in range(n)]

  pq = []

  for ab in abs:
    a,b = ab[0],ab[1]
    heapq.heappush(pq, tuple([b,a]))

  dl = 0
  tc = 0

  ans = "Yes"

  for i in range(n):
    ba = heapq.heappop(pq)
    dl = ba[0]
    tc += ba[1]
    if dl < tc:
      ans = "No"
      break
  print(ans)
  
if __name__ == "__main__":
  main()

Solution (Python):
import heapq

def main():
  n = int(input())
  abs = [tuple(map(int, input().split())) for _ in range(n)]

  pq = []

  for ab in abs:
    a,b = ab[0],ab[1]
    heapq.heappush(pq, tuple([b,a]))

  dl = 0
  tc = 0

  ans = "Yes"

  for i in range(n):
    ba = heapq.heappop(pq)
    dl = ba[0]
    tc += ba[1]
    if dl < tc:
      ans = "No"
      break
  print(ans)
  
if __name__ == "__main__":
  main()

Solution (Python):
import heapq

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

pq = []

for ab in abs:
  a,b = ab[0],ab[1]
  heapq.heappush(pq, tuple([b,a]))
  
dl = 0
tc = 0

ans = "Yes"

for i in range(n):
  ba = heapq.heappop(pq)
  dl = ba[0]
  tc += ba[1]
  if dl < tc:
    ans = "No"
    break
print(ans)

Solution (Python):
N = int(input())
A_B = [list(map(int, input().split())) for _ in range(N)]
A_B.sort(key=lambda x: x[1])
count = 0
for i in range(N):
    if count + A_B[i][0] <= A_B[i][1]:
        count += A_B[i][0]
        continue
    print("No")
    break
else:
    print("Yes")

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 = zip(A, B)

C = sorted(C)

A, B = zip(*C)

A = list(A)
B = list(B)

A.reverse()
B.reverse()

C = zip(B, A)

C = sorted(C)

B, A = zip(*C)

A = list(A)
B = list(B)

for i in range(N):
    if i!=0:
        A[i]=A[i-1]+A[i]

flag = 0

for i in range(N):
    if A[i]>B[i]:
        flag = 1

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

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

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

t = 0
ans = 'Yes'
for i in range(N):
    t += do[i][0]
    if t > do[i][1]:
        ans = 'No'
        break
print(ans)

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

Solution (Python):
import numpy as np

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

W=np.array(tmp)
ind = np.argsort(W[:,1])
W=W[ind,:]

current_time =0
for iw in W:
    current_time += iw[0]
    if current_time > iw[1]:
        print("No")
        exit()

print("Yes")
exit()

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

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

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


total = 0
for j in range(n):
  total += task[j][0]
  if(total > task[j][1]):
    print("No")
    break
  if(j == n-1):
    print("Yes")

Solution (Python):
import sys
import numpy as np
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A,B=[0]*N,[0]*N
    for i in range(N):
        A[i],B[i]=map(int,input().split())
    Bargsort=np.argsort(B)
    t=0
    for i in Bargsort:
        t+=A[i]
        if t>B[i]:
            print('No')
            exit()
    print('Yes')

if __name__ == '__main__':
    main()

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 a, b in tasks:
    time += a
    if time > b:
        print('No')
        break
else:
    print('Yes')

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

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

t = 0
for a, b in J:
    if t + a > b:
        res = 'No'
        break
    else:
        t += a
else:
    res = 'Yes'

print(res)

Solution (Python):
N = int(input())
task = []
for i in range(N):
    task.append(list(map(int, input().split())))
task.sort(key = lambda t: t[1])
ok = True

time = 0
for x in task:
    time += x[0]
    if time > x[1]:
        ok = False
        break
if ok:
    print("Yes")
else:
    print("No")

Solution (Python):
n = int(input())
l = []
current_time = 0


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

l.sort()

for e in l:
    a, b = e
    current_time = current_time + b
    if current_time > a:
        print('No')
        exit(0)

print('Yes')

Solution (Python):
N, = map(int, input().split())
As, Bs = [], []
for _ in range(N):
    A, B = map(int, input().split())
    Bs.append([B, A])
Bs.sort()
t = -1
r = "Yes"
for b, a in Bs:
    t += a
    if b > t:
        continue
    r = "No"
    break
print(r)

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

current_time = 0

for task in tasks:
    current_time += task[0]
    if current_time > task[1]:
        print("No")
        exit()

print("Yes")

Solution (Python):


import math
import sys

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

def aa(N,AB):
    clk = 0
    flg = True
    for i in range(N):
        clk += AB[i][0]
        if clk > AB[i][1]:
            flg = False
            break
    if flg:
        return "Yes"
    else:
        return "No"
print(aa(N,AB))

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

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

AB.sort()
ans = 'Yes'

for i in range(1, N+1):
  AB[i][1] += AB[i-1][1]
  if AB[i][1] > AB[i][0]:
    ans = 'No'
    break

print(ans)

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

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


time = 0
for i in ab:
    time += i[0]
    if time > i[1]:
        print("No")
        exit()

print("Yes")

Solution (Python):
n = int(input())
l = []
for _ in range(n):
    a,b = map(int,input().split())
    l.append([b,a])
l.sort()
sum = 0
check = 0
for i in l:
    a = i[1]
    b = i[0]
    sum += a
    if sum > b:
        check = 1
        break
if check == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
w = []
for i in range(n):
    a,b = map(int, input().split())
    w.append([b,a])
w.sort()
time = 0
for i in range(n):
    time+=w[i][1]
    if time > w[i][0]:
        print("No")
        exit()
    else:
        continue
print("Yes")

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

W = []
for _ in range(n):
    a, b = map(int, input().split())
    W.append((b, a))
W.sort()

t = 0
for w in W:
    t += w[1]
    if t > w[0]:
        print("No")
        exit()
print("Yes")

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

from operator import itemgetter
li=sorted(li, key=itemgetter(1), reverse=True)
li.append([None,0])
over=0

for i in range(n):
  
  if li[i][1]-li[i+1][1]<=over+li[i][0]:
    over=abs((li[i][1]-li[i+1][1])-(over+li[i][0]))
  
  else:
    over=0
  

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

Solution (Python):
def main():
	n = int(input())
	
	
	l = [list(map(int, input().split())) for _ in range(n)]
	
	
	l_s = sorted(l, key=lambda x: x[1])
	
	
	
	
	count = []
	for i in l_s:
		count.append(i[1])

	c_max = max(count)
	sime = 0
	out = 0
	for i in l_s:
		 sime += i[0]
		 
		 
		 if sime > i[1]:
		 	out = 1
		 	break
		
	if sime <= c_max and out == 0:
		print("Yes")
	elif out == 1:
		print("No")






if __name__ == '__main__':
	main()

Solution (Python):
import sys
import fractions
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab_sorted = sorted(ab, key=lambda x: x[1])

    sum_a = 0
    for a, b in ab_sorted:
        sum_a += a
        if b < sum_a:
            print('No')
            quit()
    print('Yes')

if __name__ == '__main__':
    main()

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

total = 0
for a, b in sorted_ab:
    total += a
    if total > b:
        print('No')
        exit()
print('Yes')

Solution (Python):
N = int(input())
A = [0]*N
B = [0]*N
tasks = [list(map(int,input().split())) for i in range(N)]
tasks.sort(key = lambda x:x[1])
can = True
S = 0
for i in range(N):
    S += tasks[i][0]
    if tasks[i][1] < S:
        can = False
if can:print('Yes')
else:print('No')

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

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

print('Yes')

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

n=int(input())
jobs=sorted(list(list(map(int,input().split())) for _ in range(n)), key=lambda x: x[1])
time = 0
for job in jobs:
    time+= job[0]
    if time > job[1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
def calculate(list):
    current = 0
    for item in list:
        current += item[0]
        if current > item[1]:
            return False

    return True

N = int(input())

arr = []
for i in range(N):
    arr.append([int(s) for s in input().split(" ")])

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

result = calculate(arr2)

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

Solution (Python):
n=int(input())
w=[[]for i in range(n)]
for i in range(n):
  a,b=map(int,input().split())
  w[i]=[a,b]
w.sort(key=lambda x: x[1])
dl=0
t=0
for a,b in w:
  t+=a
  dl=b
  if dl<t:
    print('No')
    exit()
print('Yes')

Solution (Python):
n=int(input())
L=[list(map(int,input().split())) for i in range(n)]
LS=sorted(L,key=lambda x:(-x[1],-x[0]))

d=LS[0][1]
i=0
while d>=0 and i<n:
	d=min(d,LS[i][1])
	d-=LS[i][0]
	i+=1

print('Yes' if d>=0 else 'No')

Solution (Python):
n = int(input())
cnt = 0
x = []
for _ in range(n):
    a, b = map(int, input().split())
    x.append([b, a])
x.sort()
for i in range(n):
    cnt += x[i][1]
    if cnt <= x[i][0]:
        pass
    else:
        print('No')
        break
else:
    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])

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

Solution (Python):




import sys


def main():
    
    input = sys.stdin.readline
    N = int(input())
    
    
    h = []
    for i in range(N):
        A, B = map(int, input().split())
        h.append((B, A))
    h.sort()
	
    time = 0
    for B, A in h:
        time += A
        if B < time:
            print("No")
            sys.exit()
    
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):

import heapq


import sys


def main():
    
    input = sys.stdin.readline
    N = int(input())
    
    
    h = []
    for i in range(N):
        A, B = map(int, input().split())
        heapq.heappush(h, (B, A))
	
    time = 0
    while len(h) > 0:
        B, A = heapq.heappop(h)
        time += A
        if B < time:
            print("No")
            sys.exit()
    
    print("Yes")


if __name__ == "__main__":
    main()

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

    A.sort()
    time = 0
    for b, a in A:
        time += a
        if time > b:
            print('No')
            exit()

    print('Yes')    



if __name__ == "__main__":
    main()

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

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

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

print('Yes')

Solution (Python):
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = [MAP() for _ in range(N)]

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


time = 0
for a in A:
	work, limit = a
	time += work
	if time > limit:
		print('No')
		sys.exit()
print('Yes')

Solution (Python):
n = int(input())
works = [[int(x) for x in input().split()] for _ in range(n)]
for i in range(n): works[i][0], works[i][1] = works[i][1], works[i][0]
works.sort()
time = 0
judge = True
for i in range(n):
  time += works[i][1]
  if time > works[i][0]:
    judge = False
    break
if judge: print("Yes")
else: print("No")

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

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

for i in range(n):
    time += ab[i][0]
    if time > ab[i][1]:
        ans = "No"
        break
else:
    ans = "Yes"

print(ans)