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 = int(input())
    task = []
    for _ in range(n):
        task.append(list(map(int, input().split())))
    time = 0
    task.sort(key=lambda x: x[1])
    answer = True
    for i in range(n):
        required_time, deadline = task[i]
        if deadline < time + required_time:
            answer = False
        else:
            time += required_time
    print("Yes" if answer else "No")


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    from operator import itemgetter
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if b < t:
            return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
AB = [tuple(map(int,input().split())) for i 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 = []
for _ in range(n):
    ab.append(list(map(int, input().split())))
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())
x = [list(map(int, input().split())) for i in range(N)]  
x.sort(key=lambda x: x[1])
limit = 0
for i in range(N):
    limit += x[i][0]
    if limit > x[i][1]:
        print('No')
        exit()
    else:
        pass
else:
    print('Yes')

Solution (Python):
N = int(input())
A=[]
B=[]




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

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

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

print('Yes')

Solution (Python):
from operator import itemgetter
N = int(input())
ls = sorted(sorted([list(map(int,input().split())) for _ in range(N)]),key=itemgetter(1))



flag = 1
t = 0
for i in range(N):
  t += ls[i][0]
  if ls[i][1] < t:
    flag = 0
    print("No")
    break

if flag == 1:
  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])
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())
tasks = []

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

tasks.sort()

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

print(ans)

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

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

tasks.sort()

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

print(ans)

Solution (Python):


import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def i() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N = I()
AB = LRI(N)

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

now = 0
for a, b in AB:
    now += a

    if now > b:
        print("No")
        break
else:
    print("Yes")

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

AB = sorted(ab, key=lambda x: x[1])
ans = "Yes"
time = 0

for x in AB:
    time += x[0]
    if time > x[1]:
        ans = "No"
        break

print(ans)

Solution (Python):
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    ab[i][0]  = b
    ab[i][1] = a
ab.sort()
ok = True
time = 0
for i in range(n):
    cost = ab[i][1]
    due = ab[i][0]
    if time+cost > due:
        ok = False 
        break
    time += cost
if ok:print('Yes')
else:print('No')

Solution (Python):
def q4():
    N = int(input())
    D = []
    for i in range(N):
        l = [int(i) for i in input().split()]
        D.append({'A': l[0], 'B': l[1]})
    D.sort(key=lambda x: x['A'])
    D.sort(key=lambda x: x['B'])

    time = 0
    ans = 'Yes'
    for d in D:
        time += d['A']
        if time > d['B']:
            ans = 'No'
            break
    print(ans)


if __name__ == '__main__':
    q4()

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

addtime=0
nowtime=0
for i in range(N):
  a=AB[i][0]
  b=AB[i][1]
  nowtime+=a
  if nowtime>b:
    print("No")
    exit()
print("Yes")

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N = iip(False)
    A = [iip(False) for i in range(N)]

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

    t = 0
    
    for i in A:
        a, b = i
        
        t += a
        if t > b:
            return "No"
    return "Yes"





def YesNo(s):
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):
    for i in s:
        print(i)

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

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

n = int(input())
task = []
time_total = [-1 for i in range(n)]
for i in range(n):
    task.append([int(i) for i in input().split()])
task_sorted = sorted(task, key = lambda x:x[1])
time_total[0] = task_sorted[0][0]
for i in range(n - 1):
    time_total[i + 1] = time_total[i] + task_sorted[i + 1][0]
for i in range(n):
    if time_total[i] > task_sorted[i][1]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
AB=sorted(AB,key=lambda x:x[1])
t=0
n=0
while n<N:
  if t+AB[n][0]<=AB[n][1]:
    t+=AB[n][0]
    n+=1
  else:
    print('No')
    exit(0)
print('Yes')

Solution (Python):
import numpy as np
N = int(input())
li = []
for n in range(N):
    li.append([int(i) for i in list(input().split())])
arr = np.array(li)
ruiseki = 0
for a in arr[np.argsort(arr[:,1], axis=0)]:
    if ruiseki + a[0] > a[1]:
            yn = "No"
            break
    else:
        yn = "Yes"
        ruiseki+=a[0]
print(yn)

Solution (Python):
from operator import itemgetter
N = int(input())

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

AB.sort(key=itemgetter(1))
time = 0
ans = "Yes"
for i in AB:
    time = time + i[0]
    if time>i[1]:
        ans = "No"
        break

print(ans)

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

time=0
for a,b in l:
  time+=a
  if time>b:
    print('No')
    exit()
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])
"""
締め切りの早いものから実施。
作業時間が締め切りをオーバーしたらFalse
"""

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

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

Solution (Python):
import numpy as np

N = int(input())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB = sorted(AB, key=lambda x: x[1])
A, B = list(zip(*AB))
B = np.array(B)
cumsum_A = np.array(A).cumsum()


ans = 'Yes' if np.count_nonzero(B >= cumsum_A) == N else 'No'
print(ans)

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

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

ans,time,count = True,0,0
while count < N and ans:
	time += AB[count][0]
	if time > AB[count][1]:
		ans = False
	count += 1

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])

time = 0
for a, limit in ab:
    time += a
    if limit < time:
        print("No")
        break
else:
    print("Yes")

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

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

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

q = 0
w = 0
flg = 0
for j in a:
  q += j[0]
  w = j[1]
  if q > w :
    flg = 1
    break

if flg == 0:
  print('Yes')
else:
  print('No')

Solution (Python):
n = int(input())
array = [[0, 0] for i in range(n)]
for i in range(n):
    array[i] = list(map(int, input().split()))
array.sort(key=lambda x:(x[1], x[0]))
time = 0
flag = True
for el in array:
    a, b = el[0], el[1]
    time += a
    if time > b:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

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

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

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

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

print('Yes')

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

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

result = 'Yes'

for job in jobs:
    time += job[0]
    if time > job[1]:
        result = 'No'
        break

print(result)

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 i in range(N):
    if time+AB[i][0] > AB[i][1]:
        print ("No")
        break
    else:
        time += AB[i][0]
else:
    print ("Yes")

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

from operator import itemgetter
ab.sort(key=itemgetter(1))

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

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

t=0
for i in l:
    b=i[0]
    a=i[1]
    if t>b-a:
        print('No')
        exit()
    else:
        t+=a
print('Yes')

Solution (Python):
n=int(input())
works=sorted([list(map(int,input().split()))[::-1] for i in range(n)])
time=0
ans='Yes'
for i in range(n):
  time+=works[i][1]
  if time>works[i][0]:
    ans='No'
print(ans)

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

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

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

ans = 0
for k,v in t:
    ans += k
    if ans > v:
        print("No")
        exit()

print("Yes")

Solution (Python):

N = int(input())
task = []

for _ in range(N):
    task.append(tuple(map(int,input().split())))

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

t = 0
ok = True
for a,b in task:
    if t+a>b:
        ok = False
        break

    t += a

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

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

ab_list = []

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

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

ct = 0

for item in ab_list:
    ct += item[0]
    if ct > item[1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

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

if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter

N = int(input())
works = [tuple(map(int, input().split())) for _ in range(N)]
works.sort(key=itemgetter(1))

total = 0
for work in works:
    total += work[0]
    if total > work[1]:
        print("No")
        break
else:
    print("Yes")

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

time = 0
res = True
for i in range(n):
    time = time + tasks[i][1]
    if time > tasks[i][0]:
        res = False
print("Yes" if res else "No")

Solution (Python):
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X = sorted(X, key = lambda x: x[1])
'''
Bi についてソートするときには当然ながら 
Aiもこれにしたがってソートしたいので、便宜上これらを 
Xi とまとめてしまいます。
'''

a = [0] * N
a[0] = X[0][0]
for i in range(1, N):
	a[i] = a[i - 1] + X[i][0]

for j in range(N):
	if a[j] > X[j][1]:
		print("No")
		exit()
print("Yes")

Solution (Python):
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n = int(input())
  works = []
  for i in range(n):
    t, limit = input_list()
    works.append((t, limit))
  sw = sorted(works, key=lambda x: x[1])
  total = 0
  for t, limit in sw:
    total += t
    if total > limit:
      print('No')
      exit(0)
  print('Yes')
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

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

n=int(input())
J=[]
for i in range(n):
    a,b=map(int,input().split())
    J.append([b,a])
J=list(sorted(J))
now=0

for i in range(n):
    now+=J[i][1]
    if now>J[i][0]:
        print("No")
        sys.exit()
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])
a_sum = 0
ans = 'Yes'
for i in range(n):
    a_sum += ab[i][0]
    if a_sum>ab[i][1]:
        ans = 'No'
        break
print(ans)

Solution (Python):
def main():
    N = int(input())
    AB = [tuple(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:
            return False
    return True

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

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

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


AB=sorted(AB, key=lambda val:val[1])

if AB[0][0]>AB[0][1]:
    print('No')
else:
    for i in range(N-1):
        AB[i+1][0]+=AB[i][0]
        if AB[i+1][0]>AB[i+1][1]:
            print('No')
            break
    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])
t=0
for i in range(n):
  t+=ab[i][0]
  if t>ab[i][1]:
    print('No')
    exit()
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])
a_sum = 0
ans = 'Yes'
for i in range(n):
    a_sum += ab[i][0]
    if a_sum>ab[i][1]:
        ans = 'No'
        break
print(ans)

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

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
cnt = 0
for i in range(n):
    cnt += ab[i][0]
    if cnt > ab[i][1]:
        print('No')
        exit()
print('Yes')

Solution (Python):


def main():
    n = int(input())
    abs = []
    for i in range(n):
        a, b = map(int, input().split())
        abs.append((a, b))
    abs = sorted(abs, key=(lambda x: x[1]))
    time = 0
    possible = True
    for i in range(n):
        time += abs[i][0]
        if time > abs[i][1]:
            possible = False
    print("Yes" if possible else "No")

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

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

a = np.array(a_list)
b = np.array(b_list)
indices = b.argsort()
a = a[indices]
b = b[indices]
if np.all(np.cumsum(a) <= b):
  print('Yes')
else:
  print('No')

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

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

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

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

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

l=[]

for i in range(N):
  x,y=[int(x) for x in input().rstrip().split()]
  l.append([x,y])

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

flag=0
now=0
ans=0
for i,j in l:
  now+=i
  if j<now:
    print("No")
    flag=1
    break
if flag==0:
  print("Yes")

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

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

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

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

cnt = 0
for i in end_jobs:
    cnt += i[0]
    if cnt > i[1]:
        print("No")
        break
else:
    print("Yes")

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

ab = sorted(ab)
total = 0

for i in range(n):
    b, a = ab[i]
    total += a
    if total>b:
        print('No')
        exit()

print('Yes')

Solution (Python):
n = int(input())
tasks = [[int(i) for i in input().split()] for i in range(n)]
sorted_tasks = sorted(tasks, key = lambda x: x[1])
passage = 0
in_time = True
for t in sorted_tasks:
    passage += t[0]
    if passage > t[1]:
        in_time = False
        break

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

Solution (Python):

n = int(input())

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

data.sort(key = lambda x: x[1])
flag = True
sum = 0
for i in range(n):
    sum += data[i][0]
    if sum > data[i][1]:
        flag = False
        break
print("Yes" if flag == True else "No")

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(N: int, A: "List[int]", B: "List[int]"):
    S = sorted([(B[i],A[i]) for i in range(N)])
    current = 0
    for i in range(N):
        current += S[i][1]
        if current > S[i][0]:
            print(NO)
            exit()
    print(YES)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
AB = [[0] * 2 for _ in range(N)]
time = [0] * N
out = 0
q = []
for i in range(N):
    tmp = list(map(int, input().split()))
    AB[i][0] = tmp[0]
    AB[i][1] = tmp[1]
    if AB[i][1] - AB[i][0] < 0:
        out = 1

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

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

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

Solution (Python):
from operator import itemgetter
n = int(input())

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

abs=sorted(ab, key=itemgetter(1))

sum=0
check=0
for i in range(n):
    sum+=abs[i][0]
    if sum <= abs[i][1]:
        continue
    else:
        check=1
        break

if check == 0:
    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])
t = 0
for a, b in ab:
    if a+t>b:
        print('No')
        break
    t += a
else:
    print('Yes')

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

    num_list = sorted(num_list, key=lambda x: x[1])
        
    time = 0
    for i in range(n):
        time += num_list[i][0]
        if time > num_list[i][1]:
            print('No')
            exit()

    print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
ab_list = list(list(map(int,input().split())) for i in range(n))
sort_list = sorted(ab_list, key=lambda x: x[1])
sum_time = sort_list[0][0]
for i in range(1,len(ab_list)):
  if sum_time <= sort_list[i-1][1]:
    sum_time += sort_list[i][0]
  else:
    print("No")
    break
else:
  if sum_time <= sort_list[-1][1]:
    print("Yes")
  else:
    print("No")

Solution (Python):
def solve():
    N = int(input())
    works = []
    for i in range(N):
        period, deadline = map(int, input().split())
        works.append((period,deadline))
    
    works.sort(key=lambda x:x[1])

    time = 0
    for period, deadline in works:
        time += period
        if time > deadline:
            print('No')
            return
    
    print('Yes')

    
if __name__ == '__main__':
    solve()

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

worktime = 0
for work, limit in task:
  worktime += work
  if worktime > limit:
    print("No")
    break
else:
  print("Yes")

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

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

ans="No"
for i,item in enumerate(C):
  if item[0]+t<=item[1]:
    t += item[0]
  else:
    break
else:
  ans="Yes"
  
print(ans)

Solution (Python):
import itertools
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
from math import factorial

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60
MOD = 10 ** 9 + 7


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

time = 0
yes = True

for i in ab:
    time += i[1]
    
    if time > i[0]:
        yes = False
        break
if yes:
    print("Yes")
else:
    print("No")

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

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x:(x[1],x[0]))
 
t = 0
ans = 'Yes'
for a,b in AB:
    t += a
    if t <= b:
        continue
    else:
        ans = 'No'
        break

print(ans)

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

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x:(x[1],x[0]))
 
t = 0
ans = 'Yes'
for a,b in AB:
    t += a
    if t <= b:
        continue
    else:
        ans = 'No'
        break

print(ans)

Solution (Python):
N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x:(x[1],x[0]))
 
t = 0
ans = 'Yes'
for a,b in AB:
    t += a
    if t <= b:
        continue
    else:
        ans = 'No'
        break

print(ans)