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
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    J=[tuple(map(int,input().split())) for _ in range(n)]
    J.sort(lambda x:x[1])
    now=0
    for a,b in J:
        now+=a
        if(now>b):
            print("No")
            return
    print("Yes")
resolve()

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

Solution (Python):
N = int(input())
W=[]
for i in range(N):
    A, B = list(map(int, input().split()))
    W.append([A, B])
W.sort(key=lambda x:x[1])
Sum = 0
f = 0
for i in range(N):
    Sum = Sum+W[i][0]
    if Sum > W[i][1]:
        print("No")
        f = f+1
        break
if f == 0:
    print('Yes')

Solution (Python):
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li.sort(key=lambda x:(x[1],x[0]*(-1)))

hiniti = 0

for i in range(n):
    hiniti += li[i][0]
    if hiniti > li[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])

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


print(ans)

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], x[0]))

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

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

t = 0
ans = 'Yes'
for i in range(N):
    if C[i][1] - C[i][0] < t:
        ans = 'No'
        break
    t += C[i][0]

print(ans)

Solution (Python):
import sys
import heapq

n = int(input())
ab = []
for i in range(n):
  tmp = list(map(int, input().split()))
  job = (tmp[1], tmp[0])
  heapq.heappush(ab, job)

today = 0
for i in range(n):
  tmp = heapq.heappop(ab)
  today += tmp[1]

  if today > tmp[0]:

    print('No')
    sys.exit()

print('Yes')

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

B_sort_index = sorted(range(len(B)), key=lambda k: B[k])

all_time = 0
for b in B_sort_index:
  all_time += A[b]
  if B[b] >= all_time:
    continue
  else:
    print("No")
    sys.exit()
print("Yes")

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

job = {}
for _ in range(N):
  a, b = map(int, input().split())
  job.setdefault(b, []).append(a)
wa = 0
flag = 0
for k, v in sorted(job.items()):
  wa += sum(v)
  if k < wa:
    print("No")
    flag = 1
    break
if flag == 0:
  print("Yes")

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

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

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

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

Solution (Python):
import math
import copy
import sys
import bisect
input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

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


main()

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

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

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

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

Solution (Python):
import sys

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

list = sorted(list, key=lambda x:x[1])
Sum = 0

for i in range(N):

    Sum += list[i][0]

    if Sum > list[i][1]:
        print("No")
        sys.exit()

print("Yes")

Solution (Python):
from operator import itemgetter
import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
ab = sorted(ab,key = itemgetter(1))
ab.insert(0,[0,0])
flag = 0
flag_2 = 0
for j in range(1,n+1):
  flag += (ab[j][1]-ab[j-1][1])-ab[j][0]
  if flag < 0:
    print("No")
    flag_2 = 1
    break
if flag_2 == 0:
  print("Yes")

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(1)

N = I()
AB = [LI() for _ in range(N)]

AB = sorted(AB, key=lambda x: x[1])
T = int(0)
for i in range(N):
    T += AB[i][0]
    if T>AB[i][1]:
        ans = -1

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

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(1)

N = I()
AB = [LI() for _ in range(N)]

AB = sorted(AB, key=lambda x: x[1])
T = int(0)
for i in range(N):
    T += AB[i][0]
    if T>AB[i][1]:
        ans = -1

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

Solution (Python):
n = int(input())
ab = []
for _ in range(n):
    ab.append([int(x) for x in input().split()])
ab.sort(key=lambda x: x[1])
punctual = "Yes"
now = 0
for ai, bi in ab:
    now += ai
    if now > bi:
        punctual = "No"
print(punctual)

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

num_list = []

for _ in range(n):
    nums = list(map(int, input().split()))
    num_list.append(nums)

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

count = 0

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

print('Yes')

Solution (Python):
N=int(input())
L=[list(map(int,input().split())) for _ in range(N)]
s=0
p=True
L=sorted(L,key=lambda x: x[1])
for l in L:
    s+=l[0]
    if l[1]>=s:
        continue
    else:
        p=False
        break
print("Yes" if p else "No")

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

Solution (Python):
N = int(input())
L = [[int(a) for a in input().split()] for _ in range(N)]

from operator import itemgetter

L.sort(key=itemgetter(1))

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

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

list1.sort(key=itemgetter(1))
megalovania = 0
for i in range(n):
	megalovania += list1[i][0]
	if megalovania > list1[i][1]:
		print("No")
		exit()
print("Yes")

Solution (Python):
import numpy as np
N = int(input())
C = []*2*N
for i in range(N):
    a,b = map(int,input().split())
    C.append(b)
    C.append(a)
D = np.array(C).reshape(N,2).tolist()
D.sort()
time = 0
flag = 1
for i in range(len(D)):
    if time + D[i][1] > D[i][0]:
        flag = 0
        break
    else:
        time += D[i][1]

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

Solution (Python):
import numpy as np
N = int(input())
A = []*N
B = []*N
C = []*2*N
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(b)
    C.append(a)
D = np.array(C).reshape(N,2).tolist()
D.sort()
time = 0
flag = 1
for i in range(len(D)):
    if time + D[i][1] > D[i][0]:
        flag = 0
        break
    else:
        time += D[i][1]

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

Solution (Python):
from operator import itemgetter

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

S = sorted(S, key=itemgetter(1))

t = 0
flag = True
for i in S:
    if t+ i[0] > i[1]:
        print("No")
        flag = False
        break

    t += i[0]

if flag:    
    print("Yes")

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

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

    time = 0
    for a, b in tasks_sorted:
        time += a
        if time <= b:
            continue
        else:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    megalomania()

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

cur = 0
for i in range(N):
  dead, time = l[i]
  if(cur + time <= dead):
    cur += time
  else:
    print("No")
    exit()

print("Yes")

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

Solution (Python):
n = int(input())
jobs = sorted([[int(x) for x in input().split()] for _ in range(n)], key=lambda x: x[1])
t = 0
for a, deadline in jobs:
    t += a
    if t > deadline:
        print('No')
        break
else:
    print('Yes')

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

for i in range(n):
    x,y = map(int,input().split())
    a.append((x,y))
    
a.sort(key = lambda x : (x[1],x[0]))
    
c = 0
ch = 1
for i in range(n):
    if(c+a[i][0]>a[i][1]):
        ch = 0
        break
    else:
        c += a[i][0]
    
if(ch==0):
    print("No")
else:
    print("Yes")

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

Solution (Python):
n=int(input())
lis=[[int(i) for i in input().split()] for j in range(n)] 
for i in range(n):
  lis[i].reverse()
lis.sort()
a=0
b=0
ans=0
for i in range(n):
  a+=lis[i][1]
  b=lis[i][0]
  if a>b:
    ans=1
    break
if ans==1:
  print("No")
else:
  print("Yes")

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

l.sort(key=lambda x: x[1])
count = 0
for i in range(N):
    count += l[i][0]
    if not count <= l[i][1]:
        print('No')
        quit()
print('Yes')

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

l.sort(key=lambda x: x[1])
count = 0
for i in range(N):
    count += l[i][0]
    if not count <= l[i][1]:
        print('No')
        quit()
print('Yes')

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

work = []

for _ in range(n):
    ai, bi = map(int, input().split())
    work.append([ai, bi])

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

deadline = 0
total = 0
success = True

for w in work:
    deadline = w[1]
    total += w[0]
    
    if deadline < total:
        success = False
        break

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

Solution (Python):


import numpy as np

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

AB = sorted(AB, key = lambda x: x[1]) 
A = np.array([AB[idx][0] for idx in range(N)])
C = A.cumsum()

for idx in range(N):
    if C[idx] > AB[idx][1]:
        print("No")
        exit()
        
print("Yes")

Solution (Python):
N = int(input())
AB=[]
for _ in range(N):
	A,B=map(int, input().split())
	AB.append([B,A])
AB.sort(reverse=True)
cur = AB[0][0]
for ab in AB:
	a = ab[1]
	b = ab[0]
	cur = min(cur, b)
	cur -= a
if(cur >= 0):
	print("Yes")
else:
	print("No")

Solution (Python):
N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
arr.sort(key=lambda x: x[1])
cnt = 0
for a,b in arr:
  cnt += a
  if cnt > b:
    flag = "No"
    break
  flag = 'Yes'

print(flag)

Solution (Python):
import sys
import heapq
n = int(input())
tasks = []
for i in range(n):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    heapq.heappush(tasks, (b, a))
_sum = 0
flg = True
for i in range(n):
    b, a = heapq.heappop(tasks)
    if _sum + a > b:
        flg = False
        break
    _sum += a
if flg:
    print("Yes")
else:
    print("No")

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

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

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

now = 0
flag = False
for l in L:
    now += l[0]
    
    if now  > l[1]:
        flag = True
        break


if flag:
    print('No')

else:
    print('Yes')

Solution (Python):
from operator import itemgetter
import sys
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l,key=itemgetter(1))
ct=0
for i in range(n):
  ct+=l[i][0]
  if ct>l[i][1]:
    print('No')
    sys.exit()
print('Yes')

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

list_ab.sort(key=lambda val: val[1])

for i in range(n):
    t += list_ab[i][0]
    if t > list_ab[i][1]:
        ans = 'No'
        break

print(ans)

Solution (Python):
from operator import itemgetter


def solve():
    t = 0
    for a, b in ab:
        t += a
        if t > b:
            return False
    return True


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

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

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

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

task = []
M = 0
for _ in range(N):
    a, b = map(int, input().split())
    task.append((b, a))

task.sort()

s = 0
ans = 'Yes'
for a, b in task:
    s += b
    if s > a:
        ans = 'No'
        break
print(ans)

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

Solution (Python):
import sys

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

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

t = 0
flag = True
for w in work:
    t += w[0]
    if t > w[1]:
        flag = False
        break

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

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



import numpy as np

N = int(readline())
AB = np.array(read().split(),np.int64)

A = AB[::2]; B = AB[1::2]

ind = B.argsort(); A = A[ind]; B = B[ind]

answer = 'Yes' if np.all(A.cumsum() <= B) else 'No'
print(answer)

Solution (Python):

import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

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

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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort(key=lambda x: x[1])
    cnt = 0
    for a, b in ab:
        cnt += a
        if b < cnt:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    slove()

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




lst.sort()





result='Yes'
time=0 

for i in range(n):
	time+=lst[i][1]
	if time>lst[i][0]:
		result='No'

print(result)

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




lst.sort()





result='Yes'
time=0 

for i in range(n):
	time+=lst[i][1]
	if time>lst[i][0]:
		result='No'
		break;

print(result)

Solution (Python):
from operator import itemgetter
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)]
ab.sort(key=itemgetter(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):
N = int(input())
AB_list = []
for i in range(N):
    AB = list(map(int, input().split()))
    AB_list.append(AB)
    
AB_list = sorted(AB_list, key=lambda x:x[1])
sum_worktime = 0
flag = True
for i in range(N):
    sum_worktime += AB_list[i][0]
    if sum_worktime > AB_list[i][1]:
        flag = False
        break

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

Solution (Python):
from sys import exit

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

t = 0
AB.sort(key=lambda x: x[1])
for A, B in AB:
    t += A
    if t > B:
        print('No')
        exit()
print('Yes')

Solution (Python):
from sys import exit

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

t = 0
data.sort(key=lambda x: x[1])
for d in data:
    t += d[0]
    if t > d[1]:
        print('No')
        exit()
print('Yes')

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

    sort_C = sorted(C)

    s = 0
    for c in sort_C:
        if s + c[1] <= c[0]:
            s += c[1]
        else:
            print('No')
            exit()

    print('Yes')

main()

Solution (Python):


import sys

n = int(input())
J = []

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


J.sort()

time = 0

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

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()
a = []
for i in range(n):
    a.append(na())
a.sort(key=lambda x: x[1])
time = 0
ans = "Yes"
for ai in a:
    time += ai[0]
    if time > ai[1]:
        ans = "No"
        break
print(ans)

Solution (Python):
from operator import itemgetter
import sys

n = int(input())
ab=[]

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

total = 0

for aabb in ab:
    total += aabb[0] 
    if total > aabb[1]:
        print("No")
        sys.exit()
        break

print("Yes")

Solution (Python):
from operator import itemgetter
n = int(input())
task = [list(map(int, input().split())) for _ in range(n)]
task.sort(key=itemgetter(1))
time = 0
flag = 0
for i in range(n):
    time += task[i][0]
    if time > task[i][1]:
        flag = 1
if flag == 0:
    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()

now=0

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

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


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

flg = True
cur = 0
for t, lm in tlm:
    cur += t
    if cur > lm:
        flg = False
        break

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

Solution (Python):
n=int(input())
a=[]
sum=0
j='Yes'
for _ in range(n):
    a.append(list(map(int,input().split())))
a.sort(key=lambda i: i[1])
for i in range(len(a)):
    sum += a[i][0]
    if sum > a[i][1]:
        j='No'
print(j)

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

time = 0

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

Solution (Python):



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

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

now = 0
for a,b in l:
    now += a
    if now > b:
        print("No")
        exit()
print("Yes")

Solution (Python):



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

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

now = 0
for a,b in l:
    now += a
    if now > b:
        print("No")
        exit()
print("Yes")

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

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

Solution (Python):
n = int(input())
li = []
work = []
for i in range(n):
    a,b = map(int, input().split())
    li.append((b,b-a,i))
    work.append(a)
li.sort()
now = 0
for bb,s,w in li:
    if now > s:
        print("No")
        exit()
    else:
        now += work[w]
print("Yes")

Solution (Python):

import sys
from heapq import heappop, heappush

sys.setrecursionlimit(10 ** 7)


YES = "Yes"  
NO = "No"  


def solve(N: int, A: "List[int]", B: "List[int]"):
    task_index = {}
    for i in range(N):
        if B[i] in task_index:
            task_index[B[i]].append(A[i])
        else:
            task_index[B[i]] = [A[i]]

    sum_task_time = sum(A)
    dead_line_pool = []
    for i in B:
        heappush(dead_line_pool, -i)

    for _ in range(N):
        last_dead_line = -heappop(dead_line_pool)
        if sum_task_time > last_dead_line:
            print('No')
            return
        else:
            sum_task_time -= task_index[last_dead_line].pop()

    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())
A = [None]*N
for i in range(N):
  A[i] = list(map(int,input().split()))
A.sort(key = lambda x:x[1])
B = [0]*len(A)
C = [0]*len(A)
for b in range(len(A)):
  B[b] = A[b][0]
for c in range(len(A)):
  C[c] = A[c][1]
jud = 'Yes'
Sum = 0
for j in range(N):
  Sum += B[j]
  if Sum > C[j]:
    jud = 'No'
    
    
print(jud)

Solution (Python):
n = int(input())
lst = []
a_sum = 0

for _ in range(n):
  a,b = map(int, input().split())
  lst.append((a,b))
  
lst = sorted(lst, key=lambda x: x[1])

for i in range(n):
  a_sum += lst[i][0]
  if lst[i][1] < a_sum:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
n = int(input())
ws = sorted([[int(i) for i in input().split()] for _ in range(n)], key=lambda x: -x[1])
t = ws[0][1]
for w in ws:
	if t > w[1]:
		t = w[1] - w[0]
	else:
		t -= w[0]
print('Yes' if t >= 0 else 'No')

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

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

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

print("Yes")

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

flag=True
time=0
for work in w:
    time+=work[0]
    if time>work[1]:
        flag=False
        break
print('Yes' if flag else 'No')

Solution (Python):
n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]
li_2 = sorted(li, key=lambda x: x[1])
time = 0
for i in range(n):
  time += li_2[i][0]
  if time <= li_2[i][1]:
    if i == n-1:
      print("Yes")
  elif time > li_2[i][1]:
    print("No")
    break;

Solution (Python):


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

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

Solution (Python):
import heapq

N = int(input())
tasks = []
for _ in range(N):
  a,b = map(int,input().split())
  if b-a < 0:
    print('No')
    exit()
  else:
    heapq.heappush(tasks,[b,-a])
    
day = 0
while len(tasks) != 0:
  b, neg_a = heapq.heappop(tasks)
  if day - neg_a > b:
    print('No')
    exit()
  else: day -= neg_a
print('Yes')

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

Solution (Python):
N = int(input())
L = []
t = 0

for i in range(N):
  a, b = map(int, input().split())
  L.append((a,b,b-a))
L = sorted(L, key = lambda x: x[1])
for a, b, c in L:
  if t > c:
    print ("No")
    break
  t += a
else:
  print ("Yes")

Solution (Python):
def main():

    N = int(input())
    A = []
    for _ in range(N):
        B = list(map(int, input().split()))
        A.append(B)
    A.sort(key=lambda x: x[1])
    time = 0
    for i in range(N):
        time += A[i][0]
        if time > A[i][1]:
            print("No")
            exit()
        else:
            continue
    print("Yes")

if __name__ == "__main__":
    main()

Solution (Python):
import heapq
import sys
input = sys.stdin.readline
 
 
def main():
    N = int(input())

    Q = []
    for _ in range(N):
        a, b = map(int, input().split())
        Q.append([b, a])
    heapq.heapify(Q)

    t = 0
    while len(Q)!=0:
        b, a = heapq.heappop(Q)
        t += a
        if t>b:
            print('No')
            return
    print('Yes')

 
if __name__ == '__main__':
    main()

Solution (Python):
import heapq
import copy
import bisect
from collections import deque

n = int(input())
a = []
b = []
tmp_a = []
tmp_b = []
flag = True

for _ in range(n):
	a_dash,b_dash = map(int,input().split())
	tmp_a.append(a_dash)
	tmp_b.append(b_dash)

k = zip(tmp_b,tmp_a)
sorted_k = sorted(k)
for b_dash,a_dash in sorted_k:
	a.append(a_dash)
	b.append(b_dash)

t = 0
qa = deque(a)
qb = deque(b)

for i in range(n):
	minimum_a = qa.popleft()
	minimum_b = qb.popleft()
	t += minimum_a
	if t > minimum_b:
		flag = False
		break

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

Solution (Python):
import sys

def main():
    def input():
        return sys.stdin.readline()[:-1]
    N = int(input())
    L = [list(map(int,input().split())) for k in range(N)]
    L = sorted(L,key = lambda x: (x[1],x[0]))
    t = 0
    for e in L:
        if t+e[0] > e[1]:
            print("No")
            exit(0)
        else:
            t += e[0]
    print("Yes")
if __name__ == '__main__':
    main()

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

def main():
    N = int(input())
    L = [list(map(int,input().split())) for k in range(N)]
    L = sorted(L,key = lambda x: (x[1],x[0]))
    t = 0
    for e in L:
        if t+e[0] > e[1]:
            print("No")
            exit(0)
        else:
            t += e[0]
    print("Yes")
if __name__ == '__main__':
    main()

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
ab = [tuple(li()) for _ in range(n)]

ab.sort(key=lambda x: x[1])
cur = 0
ok = True

for ai, bi in ab:
    cur += ai
    if cur > bi:
        ok = False
        break

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

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

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

for i in tasks:
  total += i[0]

  if total <= i[1]:
    continue
  else:
    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])
m = 0
ans = "Yes"
for a,b in AB:
    m += a
    if m > b:
        ans = "No"
        break
print(ans)

Solution (Python):
import sys
n = int(input())
task = []
for i in range(n):
    task.append(list(map(int, input().split())))
task = sorted(task, key=lambda x:x[1])
time = 0
for i in range(n):
    time += task[i][0]
    if time > task[i][1]:
        print('No')
        sys.exit()
print('Yes')