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
from math import ceil
from operator import itemgetter as get

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

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)    


def main():
    n = iinput()
    q, res = [], 0
    for i in range(n):
        q.append(tuple(rinput()))
    q = sorted(q, key = get(1))
    for i, v in q:
        res += i
        if res > v:
            print("No")
            return 0
    print("Yes")
main()

Solution (Python):
N = int(input().strip())
AB = []
for i in range(N):
    AB.append(tuple(map(int, input().strip().split())))
AB.sort(key=lambda x: x[1])
t = 0
a = []
for i in AB:
    t += i[0]
    if t > i[1]:
        a.append("NO")

if "NO" in a:
    print("No")
else:
    print("Yes")

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

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

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

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

z = zip(b_list, a_list)
z = sorted(z)
b_list, a_list = zip(*z)

count = 0
flag = True
for a, b in zip(a_list, b_list):
    count += a

    if b < count:
        flag = False
        break

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

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


if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
AB = [0]*N
for i in range(N):
    AB[i] = [int(j) for j in input().split()]
second = lambda val:val[1]
AB.sort(key = second)

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

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

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

suma = 0
flg = 1
for i in range(n):
    if a[i][1] >= a[i][0]+suma:
        suma = suma + a[i][0]
    else:
        flg = 0
        break  

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

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

time = ab[0][1] - ab[0][0]
for a,b in ab[1:]:
    time = min(time, b)
    time -= a

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

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

Solution (Python):

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

task_list.sort(key=lambda task_list: task_list[1])
time = 0
flag = True

j = 0
while(j < N):
    x = task_list[j]
    time += x[0]
    if time > x[1]:
        flag = False
        break
    j += 1

if flag:
    print("Yes")

else:
    print("No")

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

task_list.sort(key=lambda task_list: task_list[1])
time = 0
flag = True

for i in range(N):
    x = task_list[i]
    time += x[0]
    if time > x[1]:
        flag = False
        break

if flag:
    print("Yes")

else:
    print("No")

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

    from heapq import heappop, heappush
    q = []
    for i in range(n):
        a, b = map(int, input().split())
        heappush(q, (b, a))

    curr = 0
    while len(q) > 0:
        b, a = heappop(q)
        curr += a
        if curr > b:
            print("No")
            return
    print("Yes")
    
resolve()

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

def main():
    N = int(input())
    Q = []
    for _ in range(N):
        Q.append(list(map(int, input().split())))
    Q = sorted(Q, key=lambda x:x[1], reverse=True)
    t = Q[0][1]
    for q in Q:
        if t > q[1]:
            t = q[1]
        t -= q[0]
    if t >= 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter

N = int(input())
W = [list(map(int,input().split())) for i in range(N)]
W.sort(key=itemgetter(1))
time = W[0][0]
if time > W[0][1]:
    print('No')
    exit()
else:
    for i in range(1, N):
        w = W[i]
        time = time + w[0]
        if time > w[1]:
            print('No')
            exit()
print('Yes')

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

Solution (Python):
def main():
    N = int(input())
    task = []
    for _ in range(N):
        a, b = map(int, input().split())
        task.append([a, b])
    task = sorted(task, key = lambda x: x[1])
    cur = 0
    for a, b in task:
        if cur + a > b:
            return "No"
        cur += a
    return "Yes"


if __name__ == '__main__':
    print(main())

Solution (Python):

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

lim = 0
time = 0
flag = 0
for i in lst:
    lim = i[0]
    if time + i[1] <= lim:
        time += i[1]
    else:
        flag = 1
        break
if flag == 0:
    print('Yes')
else:
    print('No')

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



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

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

Solution (Python):
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
b,a=map(list, zip(*sorted(zip(b,a))) )
s=0
for i in range(n):
    s+=a[i]
    if s>b[i]:
        print("No")
        break
else:print("Yes")

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



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


def main():
    N = int(input())

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

    work.sort(key=lambda x: x[1])
    now = 0
    for a, b in work:
        now += a
        if now > b:
            print("No")
            return

    print("Yes")


if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import defaultdict

works = defaultdict(int)
n = int(input())
for i in range(n):
    time, limit = map(int, input().split())
    works[limit] += time

now = max(works)
for limit in sorted(works.keys(), reverse=True):
    if limit < now:
        now = limit
    now -= works[limit]

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

Solution (Python):

N = int(input())


DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort()



t = 0
for i in range(N):
    
    (d, c) = DeadlineCost[i]

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

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

B, A = zip(*sorted(zip(B, A)))

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

Solution (Python):

N = int(input())


DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    
    DeadlineCost.append([d, c])

DeadlineCost.sort(reverse=True)



t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

Solution (Python):

N = int(input())


DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort(reverse=True)


t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

Solution (Python):

N = int(input())


DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort(reverse=True)


t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

Solution (Python):



n = int(input().split()[0])
ab_list = []
is_ok = True

for _ in range(n):
    a, b = list(map(int, input().split()))
    ab_list.append((a, b))

ab_list = sorted(ab_list, key=lambda x: x[1])
now_t = 0
is_ok = True

for i, ab in enumerate(ab_list):
    a, b = ab
    s_deadline = b - a

    if now_t > s_deadline:
        
        is_ok = False
        break
    now_t += a

ans = 'Yes' if is_ok else 'No'
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

from operator import itemgetter as get

def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)], key=get(1)
    )
    cur = 0
    for task, deadline in A:  
        cur += task
        if cur > deadline:  
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import accumulate


def main():
    N = int(input())
    A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
    T, D = zip(*A)  
    T = list(accumulate(T))
    flg = all(t <= d for t, d in zip(T, D))  
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

from itertools import accumulate
from operator import itemgetter as get


def main():
    N = int(input())
    A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=get(1))
    T, D = zip(*A)  
    T = list(accumulate(T))
    flg = all(t <= d for t, d in zip(T, D))  
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[1]
    )
    tasks = 0
    for task, deadline in A:
        tasks += task
        if tasks > deadline:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

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

ans = True
ti = 0
for i in arr:
    if ti + i[0] > i[1]:
        ans = False
        break
    ti += i[0]
if ans:
    print("Yes")
else:
    print("No")

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

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

spend_time = 0
flg = True

for a,b in A_B:
  spend_time += a
  if spend_time > b:
    flg = False
    break
  else:
    continue

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

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

totalDay = 0
cost = 0
ans = "Yes"


jobs = [ [0]*2 for _ in range(n)]
for i in range(n):
    s, t = map(int, input().split())
    jobs[i] = [t, s]
jobs.sort()
for i in range(n):
    totalDay += jobs[i][1]
    if totalDay <= jobs[i][0]:
        continue
    else:
        ans = "No"
        break
print(ans)

Solution (Python):
import numpy as np
import itertools as it

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

np_input = np.asarray(inputs)
np_input =np.hstack((np_input,list(it.accumulate(np_input[:,:1]))))

flg=False
for row in np_input:
    if row[1] < row[2]:
        flg=True
        break

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

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

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

def detect():
    t = 0
    for a, b in ab:
        if t + a > b:
            return "No"
        t += a
    return "Yes"

print(detect())

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

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

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

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


check = 0
tmp = 0
for i in range(N):
    tmp += l[i][0]
    if tmp > l[i][1]:
        check = 1

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

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

time = 0
for x,y in lst:
    time += x
    if time > y:
        print('No')
        exit()
else:
    print('Yes')

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

time = 0
for x,y in lst:
    time += x
    if time > y:
        print('No')
        break
else:
    print('Yes')

Solution (Python):

from operator import itemgetter
N=int(input())
AB=[[int(i) for i in input().split()+[0]] for i in range(N)]
C=[0 for i in range(N)]


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

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

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 a, b in AB:
    sum += a
    if sum > b:
        print("No")
        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])
now = 0
ret = "Yes"
for a, b in AB:
    now += a
    if b < now:
        ret = "No"
        break


print(ret)

Solution (Python):
N = int(input())
job_list = list()
for i in range(N):
    job_list.append(tuple(map(int, str(input()).split())))

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

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

print('Yes')

Solution (Python):
N = int(input())
job_list = list()
for i in range(N):
    job_list.append(tuple(map(int, str(input()).split())))

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

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

print('Yes')

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

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

task.sort()

time=0
flag=True
for i in task:
    time-=i[1]
    if time>i[0]:
        flag=False
        break

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

Solution (Python):
from collections import defaultdict
n = int(input())

dct = defaultdict(list)

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

ans = 0
dct_list = sorted(dct.items())
for el in dct_list:
    ans += sum(el[1])
    if el[0] < ans:
        print("No")
        exit()
print("Yes")

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

Solution (Python):
n = int(input())
a = [list(map(int, input().split())) for k in range(n)]
a.sort(key = lambda x: x[1])
worktime = 0
deadline = 0
for i in range(n):
    if worktime <= deadline:
        worktime += a[i][0]
        deadline = a[i][1]
        if worktime <= deadline and i == n-1:
            print('Yes')
        elif worktime > deadline and i == n-1:
            print('No')
        else:
            pass
    else:
         print('No')
         break

Solution (Python):
import numpy as np

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

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


ruiseki=np.cumsum([item[0] for item in ablist])

if all([ruiseki[i]<=ablist[i][1] for i in range(n)]):
  print("Yes")
else:
  print("No")

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

time = 0
f = False

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

Solution (Python):
from operator import itemgetter
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab_s = sorted(ab, key=itemgetter(1))
ans = 'Yes'
tmp = 0
for x in ab_s:
    tmp += x[0]
    if tmp > x[1]:
        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])
j=True
x=0
for a,b in ab:
	x+=a
	if x>b:
		j=False
		break
print("Yes" if j else "No")

Solution (Python):
from operator import itemgetter as ig

INF = float("inf")
MOD = int(1e9 + 7)


def main():
    N = int(input())
    AB = (tuple(map(int, input().split())) for _ in range(N))
    ab = sorted(AB, key=ig(1))
    sum_a = 0
    for a, b in ab:
        sum_a += a
        if b < sum_a:
            print("No")
            break
    else:
        print("Yes")

main()

Solution (Python):
class Task:
    count=0
    def __init__(self,time,deadline):
        Task.count+=1
        self.time=time
        self.deadline=deadline
        self.count=Task.count
    
    def __gt__(self,other):
        if self.deadline<other.deadline:
            return True
        if self.deadline==other.deadline:
            if self.time<other.time:
                return True
            if self.time==other.time:
                if self.count<other.count:
                    return True
        return False
    
    def __lt__(self,other):
        if self.deadline>other.deadline:
            return True
        if self.deadline==other.deadline:
            if self.time>other.time:
                return True
            if self.time==other.time:
                if self.count>other.count:
                    return True
        return False
    

tasklist=[]    
n=int(input())
for i in range(n):
    time,deadline=[int(j) for j in input().split()]
    task=Task(time,deadline)
    tasklist.append(task)
check=0
time=0
tasklist.sort()



while tasklist:
    task=tasklist.pop()
    if task.time+time>task.deadline:
        check+=1
        print("No")
        break
    else:
        time+=task.time
        
if check==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])


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

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

a.sort(key=lambda x:x[1])
time=0
over=0
for i in range(n):
    if time+a[i][0]>a[i][1]:
      over=1
      break
    else:
        time+=a[i][0]

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

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

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

now = 0
msg = 'Yes'
for task in tasklist:
    if now + task[0] > task[1]:
        msg = 'No'
        break
    else:
        now += task[0]

print( msg )

Solution (Python):
import heapq
n = int(input())
A = []
for _ in range(n):
    a, b = map(int, input().split())
    heapq.heappush(A, [b, a])
a_sum = 0
f = 1
for _ in range(n):
    b, a = heapq.heappop(A)
    a_sum += a
    if a_sum > b:
        f = 0
        break
print(["No", "Yes"][f])

Solution (Python):
import heapq
n = int(input())
A = []
for _ in range(n):
    a, b = map(int, input().split())
    heapq.heappush(A, [b, a])
a_sum = 0
f = 1
for _ in range(n):
    b, a = heapq.heappop(A)
    a_sum += a
    if a_sum > b:
        f = 0
        break
print(["No", "Yes"][f])

Solution (Python):
import itertools

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

n=getint()
a=[getints() for _ in range(n)]
a=list(sorted(a,key=lambda s: s[1]))

now=0
ok=True
for i in range(n):
    now += a[i][0]
    if now > a[i][1]:
        ok = False

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

Solution (Python):
from operator import itemgetter
a = int(input())
l = []
for i in range(a):
    t,T = map(int,input().split())
    l.append((t,T))
l = sorted(l, key=itemgetter(1), reverse=False)

E = 0
S = 0 
s = 0
for i , j in l :
    E += abs(E-j)
    S += i
    if S>E:
        s=1 
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')

y(s)

Solution (Python):
from operator import itemgetter
a = int(input())
l = []
for i in range(a):
    t,T = map(int,input().split())
    l.append((t,T))
l = sorted(l, key=itemgetter(1), reverse=False)

E = 0
S = 0 
s = 0
for i , j in l :
    E += abs(E-j)
    S += i
    if S>E:
        s=1 
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')

y(s)

Solution (Python):
from operator import itemgetter


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

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

    acc = 0
    answer = 'Yes'
    for a, b in ab:
        acc += a
        if acc > b:
            answer = 'No'
            break

    print(answer)


main()

Solution (Python):
def solve():
    n = int(input())
    ab = sorted(list(list(map(int, input().split())) for _ in range(n)), key=lambda x: x[1])
    total_time = 0
    for a, b in ab:
        total_time += a
        if b < total_time:
            return "No"
    return "Yes"


if __name__ == "__main__":
    print(solve())

Solution (Python):
n=int(input())
m=[]
for i in range(n):
    [p,q]=[int(x) for x in input().split()]
    m.append([p,q])
m.sort(key=lambda x:x[1])
su=0
flag=True
for i in m:
    su+=i[0]
    if su>i[1]:
        flag=False
        break
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
d=[]
for n in range(N):
    d.append(list(map(int,input().split())))
d_1=sorted(d,key=lambda d:d[1])
t=0
for n in range(N):
    t+=d_1[n][0]
    if t>d_1[n][1]:
        print("No")
        exit(0)
print("Yes")

Solution (Python):
n=int(input())
A = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
  A[i][0],A[i][1]=map(int,input().split())
  

A = sorted(A, key=lambda x: x[1])
sum=0
for i in range(n):
  sum+=A[i][0]
  if sum>A[i][1]:
    print('No')
    break
  if i==n-1:
    print('Yes')

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

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

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

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

ok_time = 0
dame_time = 0

answer = "Yes"
for i in range(N):
    ok_time = C[i][1]
    dame_time += C[i][0]
    if dame_time > ok_time:
        answer = "No"
print(answer)

Solution (Python):
import sys

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


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

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

print("Yes")

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

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

flag = True
time = 0
for elem in sch:
    need, limit = elem
    time += need
    if time > limit:
        flag = False
        break

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

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

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

Solution (Python):

from operator import itemgetter as ig
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
    A[i], B[i] = (int(_) for _ in input().split())
AB = sorted([(A[i], B[i])for i in range(N)], key = ig(1))
last = 0
ans = True
for i in range(N):
    last += AB[i][0]
    if last <= AB[i][1]:
        continue
    else:
        ans = False
        break
if ans:
    print("Yes")
else:
    print("No")

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

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


import numpy as np
task = np.array(task)


newtask = task[np.argsort(task[:,1])]

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

Solution (Python):
import sys

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
t = 0

for i in range(n):
    if t+ab[i][0] > ab[i][1]: print("No"); sys.exit()
    else: t += ab[i][0]
else:
    print("Yes")

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

t_sort=sorted(t,key=lambda x: x[1])
for i in range(n):
    time+=t_sort[i][0]
    if time>t_sort[i][1]:
        print("No")
        break
    else:
        if i==(n-1):
            print("Yes")

Solution (Python):


n = int(input())


hash = {}
for _ in range(n):
    a, b = map(int, input().split())
    if b in hash:
        hash[b].append(a)
    else:
        hash[b] = [a]
arr = []
for k, v in hash.items():
    arr.append([k, v])
arr = list(sorted(arr, key=lambda x: x[0]))

count = 0
for a in arr:
    for ai in a[1]:
        if count + ai > a[0]:
            print("No")
            exit()
        else:
            count += ai
print("Yes")

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

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

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

t = 0
flg = True
for w in works:
    t += w[0]
    if t > w[1]:
        flg = False

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

Solution (Python):


N = int(input())
a_b = [[int(x) for x in input().split()] for i in range(N)]
sorted_tasks = sorted(a_b, key=lambda x: x[1])
current_time = 0
is_no = False
for task in sorted_tasks:
    current_time += task[0]
    if task[1] < current_time:
        is_no = True
        break

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

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

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

isYes = True
totalA = 0
for i in range(N):
    totalA += arr[i][0]
    if totalA > arr[i][1]:
        isYes = False

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