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):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque

from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n=I()
data=MXI()
s=sorted(data, key=lambda x: x[1])
sm=0
for i in range(n):
    sm+=s[i][0]
    if sm<=s[i][1]:
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

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

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

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

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

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



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

count=0
for i in range(n):
    count+=sort_ab[i][0]
    if sort_ab[i][1]<count:
        print("No")
        break
else:
    print("Yes")

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

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

count=0
for i in range(n):
    count+=sort_ab[i][0]
    if sort_ab[i][1]<count:
        print("No")
        break
else:
    print("Yes")

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


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

count=0
for i in range(n):
    count+=sort_ab[i][0]
    if sort_ab[i][1]<count:
        print("No")
        break
else:
    print("Yes")

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

ans = "Yes"
day = 0
for i in range(n):
    day += AB[i][0]
    if day > AB[i][1]:
        ans = "No"

print(ans)

Solution (Python):
n = int(input())
job = [[0, 0] for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    job[i][0] = b
    job[i][1] = a
job.sort()

ans = "Yes"
t = 0
for i in range(n):
    t += job[i][1]
    if t > job[i][0]:
        ans = "No"

print(ans)

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

Solution (Python):
import sys
from operator import itemgetter
readline = sys.stdin.buffer.readline
MOD = 10**9+7
INF = float('inf')

def main():
    N = int(readline())
    AB = []
    for _ in range(N):
        a, b = map(int, readline().split())
        AB.append((a,b))
    AB.sort(key=itemgetter(1))
    total = 0
    ans = 'Yes'
    for i in range(N):
        a = AB[i][0]
        b = AB[i][1]
        total += a
        if total>b:
            ans = 'No'
            break
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    lis=[]
    for i in range(n):
        a,b=map(int,input().split())
        lis.append((b,a))
    lis.sort()
    time=0
    for l in lis:
        time+=l[1]
        if time>l[0]:
            print("No")
            break
    else:
        print("Yes")

if __name__=='__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    AB = [[int(e) for e in input().split()] for i in range(n)]

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

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

    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

import numpy as np

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

AB = np.array(AB)
A_cumsum = np.cumsum(AB[:, 0])
bool = (A_cumsum <= AB[:, 1]).all()
print('Yes' if bool else 'No')

Solution (Python):
'''
締切が早いやつからこなしていきたい
BiでソートしてAiまでの累積時間が時刻Biを超えてないかを
チェックしていけば良さそう
Biについてソートするときには当然ながらAiも
これにしたがってソートしたいので、便宜上これらをXiと
まとめる　Satoooh
'''
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X = sorted(X, key = lambda x: x[1])


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):
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:x[1])

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

Solution (Python):
n = int(input())
T = []
s = 0
for _ in range(n):
    a, b = list(map(int, input().split()))
    T.append((a, b))
    s += a
T = sorted(T, key=lambda x: x[1])[::-1]
f = 0
for i, (a, b) in enumerate(T):
    if b < s:
        f = 1
        break
    s -= a
if f == 0:
    print('Yes')
else:
    print('No')

Solution (Python):


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

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

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

cnt = 0
flag = True

for i in t:
  cnt += i[0]

  if cnt > i[1]:
    flag = False
    break

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

Solution (Python):
N = int(input())
T = [list(map(int, input().split())) for _ in range(N)]
T = sorted(T, key=lambda t: t[1])
for i in range(N-1):
    T[i+1][0] += T[i][0]

print('Yes' if all([T[i][0] <= T[i][1] for i in range(N)]) else 'No')

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
AB = [LIST() 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")
		break
else:
	print("Yes")

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        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 i in range(N):
            time+=L[i][0]
            if time > L[i][1]:
                return 'No'

        return 'Yes'

    print(main())


resolve()

Solution (Python):
def main():
    n=int(input())
    task=[]
    for i in range(n):
        a,b=map(int,input().split())
        task.append([b,a])
    task.sort()
    t=0
    ans="Yes"
    for i in range(n):
        t+=task[i][1]
        if t>task[i][0]:
            ans="No"
            break
    print(ans)
if __name__=="__main__":
    main()

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

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

ab =sorted(ab, key = lambda x:x[1])
ans = 0
for i in ab:
    ans+=i[0]
    if ans > i[1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
from operator import itemgetter

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

AB.sort(key=itemgetter(1))

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

Solution (Python):
import sys
from operator import itemgetter
n = int(input())
a = [0]*n
b = [0]*n
box = []
for i in range(n):
     a[i],b[i] = map(int,input().split())
     box.append((a[i],b[i]))
box1 = sorted(box,key=itemgetter(1,0))
ans=0
for i in range(n):
     ans += box1[i][0]
     if ans > box1[i][1]:
          print('No')
          sys.exit()

print('Yes')

Solution (Python):
import sys
n=int(input())
lst=[]
for i in range(n):
  a,b=map(int,input().split())
  lst.append([a,b])
lst.sort(key=lambda x:x[1])
time=0
for i in range(n):
  if time+lst[i][0]<=lst[i][1]:
    time+=lst[i][0]
  else:
    print('No')
    sys.exit()
print('Yes')

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

prefix_cost = []
current_cost = 0
for i in range(N):
    current_cost += data[i][1]
    prefix_cost.append(current_cost)

for i in range(N):
    if not prefix_cost[i] <= data[i][0]:
        print('No')
        exit()

print('Yes')

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

time=0
error=0
for j in range(N):
    time += L[j][0]
    if time > L[j][1]:
        error += 1
if error >0:
    print('No')
else:
    print('Yes')

Solution (Python):

import sys
n = int(input())
a = [0]*n
b = [0]*n

for i in range(n):
    ab = list(map(int, input().split()))
    a[i] = [i, ab[0]]
    b[i] = [i, ab[1]]
b = sorted(b, key=lambda x: x[1])
time = 0
for i in range(n):
    time += a[b[i][0]][1]

    if time > b[i][1]:
        print("No")
        sys.exit()
print('Yes')

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

work.sort()

now=0
for i in range(0,N):
    b,a=work[i]
    now+=a
    if now>b:
        print('No')
        exit()

print('Yes')

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

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

time = float("inf")
for take, due in tasks:
    time = min(due, time) - take

print("No" if time < 0 else "Yes")

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

time = float("inf")
while tasks:
    take, due = tasks.pop()
    time = min(due, time) - take

print("No" if time < 0 else "Yes")

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

Solution (Python):
from sys import stdin
from collections import deque
N=list(map(int,stdin.readline().strip().split()))[0]

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

data=sorted(data,key=lambda x:(x[1]))
d=deque(data)
while(len(d)!=0):
    A,B=d.popleft()
    if B>=t+A:
        t+=A
    else:
        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])
w=0
ans='Yes'
for i in range(n):
  w+=ab[i][0]
  if w<=ab[i][1]:
    pass
  else:
    ans='No'
    continue
print(ans)

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

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

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

    total_time = 0
    for j in range(n):
        total_time += time_task[j][1]
        limit = time_task[j][0]
        if total_time > limit:
            return 'No'
    return 'Yes'

print(task())

Solution (Python):
def solve():
    N = int(input())
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda t:(t[1],-t[0]))
    time = 0
    ret = True
    for ab in AB:
        time += ab[0]
        if time > ab[1]:
            ret = False
            break
            
    print('Yes' if ret else 'No')
    
solve()

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

Solution (Python):

import sys
from sys import stdin

n = int(stdin.readline().rstrip())
x = [list(map(int, stdin.readline().rstrip().split())) for i in range(n)]

x.sort(key=lambda x: x[1])
sup = 0
for xi in x:
    sup += xi[0]
    if sup > xi[1]:
        print('No')
        sys.exit()
print('Yes')

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

n = int(input())
time = []
flag = True
now = 0

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

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

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

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

Solution (Python):
N = int(input())
works = []
for i in range(N):
  a, b = list(map(int, input().split()))
  work = {"time": a, "expired": b}
  works.append(work)

works = sorted(works, key=lambda x:x["expired"])

time = 0
res = "Yes"
for w in works:
  time += w["time"]
  if w["expired"] < time:
    res = "No"
    break

print(res)

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

import sys
sjobs = sorted(jobs, key=lambda x:x[1])

now = 0
for delta, limit in sjobs:
    now += delta
    if now > limit:
        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])
time = 0
for a, b in ab:
    time += a
    if time <= b:continue
    print('No')
    exit()
print('Yes')

Solution (Python):
n=int(input())
t=0
for d,s in sorted(list(map(int,input().split()))[::-1] for _ in range(n)):
  t+=s
  if t>d: print('No'); exit()
print('Yes')

Solution (Python):
n=int(input())
t=0
for s,d in sorted([list(map(int,input().split())) for _ in range(n)],key=lambda k:k[1]):
  t+=s
  if t>d: print('No'); exit()
print('Yes')

Solution (Python):
import sys
n=int(input())
t=0
for s,d in sorted([list(map(int,sys.stdin.readline().split())) for _ in range(n)],key=lambda k:k[1]):
  t+=s
  if t>d: print('No'); break
else: print('Yes')

Solution (Python):
from operator import itemgetter

N = int(input())
table = [[int(i) for i in input().split()] for _ in range(N)]
table.sort(key=itemgetter(1))
limit = 0

for i in table:
    limit += i[0]
    if i[1] < limit:
        print("No")
        exit()

print("Yes")

Solution (Python):
N =int(input())
List = []
for _ in range(N):
  A, B = map(int, input().split())
  List.append([A,B])
List = sorted(List,key=lambda x: x[1],reverse = True)
Limit = List[0][1]
for item in List:
  Limit = min(item[1],Limit) - item[0]
  if Limit < 0:
    print('No')
    exit()
print('Yes')

Solution (Python):
N=int(input())
t=0
AB=sorted([list(map(int,input().split())) for _ in range(N)],key=lambda val:val[1])
for A,B in AB:
    t+=A
    if t>B:
        print("No");exit()
print("Yes")

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

lst = []
for i in range(N):
  N, K = map(int, input().split())
  lst.append((N, K))

lst.sort(key=lambda tup: tup[1])
time = 0
for x in lst:
  time += x[0]
  if time > x[1]:
    print("No")
    exit()

print("Yes")

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

lst = []
for i in range(N):
  N, K = map(int, input().split())
  lst.append((K-N, N, K))

lst.sort(key=lambda tup: tup[2])
count = 0
for ind, x in enumerate(lst):
  if count > x[0]:
    print("No")
    exit()
  count += x[1]

print("Yes")

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

lst = []
for i in range(N):
  N, K = map(int, input().split())
  lst.append((K-N, N, K))

lst.sort()
lst.sort(key=lambda tup: tup[2])
count = 0
for ind, x in enumerate(lst):
  if count > x[0]:
    print("No")
    exit()
  count += x[1]

print("Yes")

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

lst = []
for i in range(N):
  N, K = map(int, input().split())
  lst.append((K-N, N, K))

lst.sort()
lst.sort(key=lambda tup: tup[2])
count = 0
for ind, x in enumerate(lst):
  if count > x[0]:
    print("No")
    exit()
  count += x[1]

print("Yes")

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

lst = []
for i in range(N):
  N, K = map(int, input().split())
  lst.append((K-N, N, K))

lst.sort()
lst.sort(key=lambda tup: tup[2])
count = 0
for ind, x in enumerate(lst):
  if count > x[0]:
    print("No")
    exit()
  count += x[1]

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

current_time = 0
for A, B in AB:
    current_time += A
    if current_time > B:
        print("No")
        exit()

print("Yes")

Solution (Python):
x = int(input())
job = []
for i in range(x):
    j, t = list(map(int, input().split()))
    job.append([t, j])
fi = 0
f = 0
job = sorted(job)
for i in range(x):
    if f + job[i][1] > job[i][0]:
        print("No")
        fi = 1
        break
    else:
        f += job[i][1]
if fi == 0:
    print("Yes")

Solution (Python):
import numpy as np
n = int(input())
limit_list = []
time_list = []
for i in range(n):
    a,b = map(int,input().split())
    time_list.append(a)
    limit_list.append(b)
now_time = 0
flag = True
for i in np.argsort(limit_list):
    tmp =  limit_list[i] -time_list[i] -now_time
    if tmp >=0:
        now_time += time_list[i]
    else:
        flag = False
        break
if flag:
    print('Yes')
    
else:
    print('No')

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

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

for i in range(N):
    if now + T[i][1] > T[i][0]:
        print("No")
        sys.exit()
    else:
        now += T[i][1]

print("Yes")

Solution (Python):
n = int(input())
works = []
flag = True
for i in range(n):
    works.append(list(map(int, input().split())))
sorts = sorted(works, key=lambda x: x[1])
time = 0
for i in range(n):
    time += sorts[i][0]
    if time > sorts[i][1]:
        print('No')
        flag = False
        break
if flag:
    print('Yes')

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

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














N = int(input())
A = {}
B = {}
for i in range(N):
    a,b = map(int,input().split())
    A[i] = a
    B[i] = b
B = sorted(B.items(),key = lambda x:x[1])
time = 0
c = 0
for i in range(N):
    index = B[i][0]
    a = A[index]
    time += a
    if B[i][1] < time:
        c = 1
        break
if c == 0:
    print("Yes")
else:
    print("No")

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

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

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

Solution (Python):

import sys
import numpy as np

YES = "Yes"  
NO = "No"  


def solve(N: int, A: "List[int]", B: "List[int]"):
                    

    tasks = [(b, a) for a,b in zip(A,B)]
    tasks = sorted(tasks)
    times = [time for lim, time in tasks]
    lims = [lim for lim, time in tasks]

    c = np.cumsum(times)
    if (c <= lims).all() :
        print(YES)
    else:
        print(NO)

    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):
import operator  as op
import itertools as itr

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

	ABs = sorted(AB, key = op.itemgetter(1))
	it  = itr.accumulate(ABs, lambda t1, t2: (t1[0]+t2[0], t2[1]))
	if all(map(lambda t: t[0] <= t[1], it)):
		print("Yes")
	else:
		print("No")

	return


main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
ab = [inpl() for _ in range(n)]
now = 0
ab.sort(key = lambda x:x[1])


for i in range(n):
    a,b = ab[i]
    now += a
    if now > b:
        print('No')
        
        break
else:
    print('Yes')

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

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

time=0
flag=True
for cost,limit in task:
    time+=cost
    if time>limit:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')

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

Solution (Python):


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

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

Solution (Python):



N = int(input())


cost_list = []
for i in range(N):
    A, B = map(int, input().split())
    cost_list.append([A, B])
cost_list.sort(key=lambda x: x[1])
time_cost = 0


is_ok = True
for c in cost_list:
    A = c[0]
    B = c[1]
    time_cost += A
    if time_cost>B:
        is_ok = False
        break


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

Solution (Python):
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
J = [list(map(int, input().split())) for _ in range(N)]
"""
J: [かかる時間, 締め切り時刻]
"""


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


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

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

    ab.sort()
    now = 0
    for i in range(n):
        now += ab[i][1]
        if now > ab[i][0]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
X = [[int(i) for i in input().split()] for __ in range(N)]
X = sorted(X,key = lambda x:x[1])

a = [0] * N
a[0] = X[0][0]
for  i in range(1,N):
    a[i] = a[i-1] + X[i][0]
for i in range(N):
    if a[i] > X[i][1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
import sys
from operator import itemgetter

def solve():
    input = sys.stdin.readline
    N = int(input())
    work = [[int(i) for i in input().split()] for _ in range(N)]
    work.sort(key = itemgetter(1))
    currentTime = 0
    for i in range(N):
        a, b = work[i]
        if a + currentTime <= b:
            currentTime += a
        else:
            print("No")
            break
    else: print("Yes")

    return 0

if __name__ == "__main__":
    solve()

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

Solution (Python):

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

res = 0
for i in range(N):
    res += X[i][0]
    if res > X[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([b,a])
ab.sort()
time = 0
ok = True
for i in range(n):
    a = ab[i][1]
    b = ab[i][0]
    if time + a > b:
        ok = False
        break
    time +=a
if ok :print('Yes')
else:print('No')

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

Solution (Python):
n = int(input())
W = []
for i in range(n):
    a, b = map(int, input().split())
    W.append((a, b))
W.sort(key=lambda x: x[1])
x = 0
for i in range(n):
    a, b = W[i]
    x += a
    if x > 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])

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

Solution (Python):
N = int(input())
ls = []
now = 0
simekiri = 0
flag = 0
for i in range(N):
    a,b = map(int,input().split())
    ls.append([b,a])
ls.sort()
for i in range(len(ls)):
    simekiri = ls[i][0]
    now += ls[i][1]
    if now > simekiri:
        print("No")
        flag += 1
        break
if flag == 0:
    print("Yes")

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

ok = True
time = 0
for a, b in AB:
  time += a
  if time <= b: continue
  else:
    ok = False
    break
print("Yes" if ok else "No")

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

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    tasks=[tuple(map(int, input().split())) for _ in range(N)]

    from operator import itemgetter
    tasks.sort(key=itemgetter(1))
    t=0
    for task in tasks:
        t += task[0]
        if t > task[1]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):



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

AB.sort()
t = 0
for i in range(n):
    t += AB[i][1]
    if t > AB[i][0]:
        print('No')
        exit()
else:
    print('Yes')

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
ab = [LIST() for _ in range(n)]
ab.sort(key=lambda x:x[1])
tim = 0
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    if tim + a > b:
        print('No')
        exit()
    tim += a
print('Yes')

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