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

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

Solution (Python):
n = int(input())
task_time = {}
task_limit = {}
for i in range(1,n+1):
    a,b = map(int,input().split())
    task_time[i] = a
    task_limit[i] = b

task_limit_sorted = sorted(task_limit.items(), key=lambda x:x[1])

time = 0
for i in task_limit_sorted:
    time += task_time[i[0]]
    if task_limit[i[0]] < time:
        print ("No")
        exit ()

print ("Yes")

Solution (Python):
N = int(input())
Dic = dict()
for i in range(N):
    A,B = map(int,input().split())
    if B not in Dic:
        Dic[B] = A
    else:
        Dic[B] += A
Deadlines = sorted(Dic)
Time = 0
for Deadline in Deadlines:
    if Time+Dic[Deadline] <= Deadline:
        Time += Dic[Deadline]
    else:
        Ans = 'No'
try:
    if Ans =='No':
        print(Ans)
except:
    print('Yes')

Solution (Python):
N=int(input())
task=[tuple(map(int,input().split())) for _ in [0]*N]
task.sort(key=lambda x:x[1])
time=0
flg=True
for a,b in task:
    time+=a
    if b<time:
        flg=False
print(['No','Yes'][flg])

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    AB = [LI() for _ in range(N)]
    AB.sort(key=lambda x: x[1])

    ans = 'Yes'
    t = 0
    limit = 0
    for A, B in AB:
        limit = B
        t += A
        if t > limit:
            ans = 'No'
            break

    print(ans)

if __name__ == '__main__':
    resolve()

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

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

	tasks.sort()

	t = 0
	for task in tasks:
		t += task[1]
		if t > task[0]:
			return False
	return True

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

Solution (Python):

"""
Created on Wed Sep 16 12:27:12 2020

@author: liang
"""

N = int(input())
W = list()
for i in range(N):
    a, b = map(int, input().split())
    W.append((a,b))

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

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

Solution (Python):
n=int(input())
task_list=[]
for i in range(n):
    task_list.append([int(x) for x in input().split()])
import operator
task_list.sort(key=operator.itemgetter(1))
time_now=0
for i in range(n):
    time_now+=task_list[i][0]
    if time_now>task_list[i][1]:
        print("No")
        exit()
    
print("Yes")

Solution (Python):
def abc131d_megalomania():
    n = int(input())
    d = []
    for _ in range(n):
        d.append(list(map(int, input().split())))
    d.sort(key=lambda x: x[1])
    t = 0
    for item in d:
        t += item[0]
        if t > item[1]:
            print('No')
            return
    print('Yes')
abc131d_megalomania()

Solution (Python):
N=int(input())
BA=[]
for _ in range(N):
    A,B=map(int,input().split())
    BA.append([B,A])
BA.sort()
T=0
for i in range(N):
    T+=BA[i][1]
    if T>BA[i][0]:
        print("No")
        break;
else:
    print("Yes")

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
ab = [na() for _ in range(n)]
ab.sort(key=itemgetter(1, 0))
now = 0
ans = 'Yes'
for i in range(n):
    a, b = ab[i]
    now += a
    if now > b:
        ans = 'No'
        break
print(ans)

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

    ba_lst = [0] * n
    for i in range(n):
        a = ab_lst[i][0]
        b = ab_lst[i][1]
        ba = [b, a]
        ba_lst[i] = ba
    ba_lst.sort()

    lst = []
    b = ba_lst[0][0]
    a = ba_lst[0][1]
    for i in range(n):
        b_tmp = ba_lst[i][0]
        a_tmp = ba_lst[i][1]

        if b == b_tmp:
            if i != 0:
                a += a_tmp
            if i == n - 1:
                lst.append([b, a])

        else:
            lst.append([b, a])
            b = b_tmp
            a = a_tmp

    if len(lst) > 1:
        if ba_lst[-1][0] != ba_lst[-2][0]:
            lst.append([ba_lst[-1][0], ba_lst[-1][1]])


    accumulate = 0
    flag = True
    for i in range(len(lst)):
        accumulate += lst[i][1]
        if accumulate > lst[i][0]:
            flag = False
            break

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


if __name__ == '__main__':
    main()

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    l = [i_list() for i in range(n)]
    l = sorted(l, key= lambda x: x[1])

    trial = 0
    for i,k in l:
        trial += i
        if trial > k:
            print("No")
            exit()
    print("Yes")


if __name__=="__main__":
    main()

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):



import numpy as np


N=int(input())
ls=[]
for _ in range(N):
    p=list(map(int,input().split()))
    ls.append(p)

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


time=0

for i in range (N):
    time+=ls[i][0]
    if ls[i][1] < time:
        print("No")
        exit()
    else:
        pass

print("Yes")

Solution (Python):
from operator import *
N = int(input())
AB = [list(map(int,input().split())) for n in range(N)]
AB = sorted(AB,key=itemgetter(1))
ans = "Yes"
T = 0

for a,b in AB:
  T+=a
  if b<T:
    ans = "No"

print(ans)

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

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

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

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

Solution (Python):
def main():
    n = int(input())
    adic = dict()
    bdic = dict()

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

    for dic in bdic2:
        shigoto = dic[0]
        time += adic[shigoto]
        if time > dic[1]:
            print("No")
            exit()
    
    print('Yes')





if __name__ == "__main__":
    main()

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
AB = []
for _ in range(N):
    a, b = mapint()
    AB.append((a, b))
AB.sort(key=lambda x:x[1])
now = 0
for i in range(N):
    a, b = AB[i]
    if b-a<now:
        print('No')
        break
    now += a
else:
    print('Yes')

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

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

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

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

print("Yes")

Solution (Python):
import numpy as np
N = int(input())
AB = ['']*N
for i in range(N):
  AB[i] = list(map(int, input().split()))


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

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

Solution (Python):
n = int(input())
arr = {}
for i in range(n):
  a,b= map(int, input().split( ))
  if b in arr:
    arr[b] += a
  else:
    arr[b] = a
time = 0
arrs = sorted(arr.items(), key=lambda x:x[0])
for lin in arrs:
  time += lin[1]
  if lin[0] < time:
    print('No')
    exit()
print('Yes')

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

Solution (Python):
import pprint
n = int(input())
a = [[0]*2 for i in range(n)]
memo = 0 
ahozon = 0
for i in range(n):
  a[i][0],a[i][1]=map(int,input().split())
a.sort(key=lambda x: x[1])
for j in range(n):
  if(memo<=1):
    if(a[j][1]-a[j][0]-ahozon>=0):
      ahozon+=a[j][0]
    else:
      memo +=1
if(memo>=1):
  print("No")
else:
  print("Yes")

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
work = []
for _ in range(N):
    a,b = mint()
    work.append([a,b])
work.sort(key=lambda x:x[1])
t = 0
ans = True
for a,b in work:
    if t+a>b:
        ans = False
        break
    t += a
judge(ans)

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

Solution (Python):
def main():
	N = int(input())
	tasks = []
	for i in range(N):
		A, B = [int(x) for x in input().split(" ")]
		tasks.append({
			"time" : A,
			"deadline" : B
		})
	tasks.sort(key=lambda task: task["deadline"])
	tot = 0
	in_time = "Yes"
	for i in range(len(tasks)):
		t = tasks[i]["time"]
		d = tasks[i]["deadline"]
		tot += t
		if tot > d:
			in_time = "No"
			break
	print(in_time)

main()

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

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

n = 0
d = 0
f = 0
for i in range(N):
    n += t[i][0]
    if n > t[i][1]:
        f = 1
        break

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

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

Solution (Python):
N = int(input())
tasks = []
for i in range(N):
    A, B = [int(x) for x in input().split()]
    tasks.append([B, A])
tasks.sort()

ok = True
S = 0
for i in range(N):
    B, A = tasks[i][0], tasks[i][1]
    S += A
    if S > B:
        ok = False
        break

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

Solution (Python):
N = int(input())
tasks = []
for i in range(N):
    A, B = [int(x) for x in input().split()]
    tasks.append([B, A])
tasks.sort()

ok = True
S = 0
for i in range(N):
    B, A = tasks[i][0], tasks[i][1]
    S += A
    if S > B:
        ok = False
        break

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

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

Solution (Python):
import sys


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

time = 0

for i in range(N):
  time += jobs[i][0]

  if time > jobs[i][1]:
    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])
total=0
for i in range(N):
    total+=AB[i][0]
    if total<=AB[i][1]:
        continue
    else:
        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])

hours = 0

ans = "Yes"
for pair in a:
    hours += pair[0]
    deadline = pair[1]


    if hours > deadline:
        ans = "No"
        break

print(ans)

Solution (Python):








def solve(N, ABs):
    ABs.sort(key=lambda x: x[1])
    time = 0
    ans = 'Yes'
    for A, B in ABs:
        time += A
        if time > B:
            ans = 'No'
            break
    print(ans)


if __name__ == '__main__':
    
    N = int(input())
    
    ABs = [[int(i) for i in input().split()] for _ in range(N)]
    
    solve(N, ABs)

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

Solution (Python):

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


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

result = 'Yes'
t = 0
for i,j in work:
    t += i
    if t>j:
        result = 'No'
        break
print(result)

Solution (Python):









import os
import sys




def main():
    n = int(input())
    S = []
    for _ in range(n):
        S.append(list(map(int, input().split())))
    S.sort(key=lambda x:x[1])
    current_time = 0
    for s in S:
        current_time += s[0]
        if current_time <= s[1]:
            pass
        else:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import accumulate
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
a, b = zip(*ab)
a = list(a)
b = list(b)
a = list(accumulate(a))
for i, j in zip(a, b):
    if i > j:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
import heapq

def solve():
    N = int(input())
    que = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(que, (b, a))
    now = 0
    while que:
        b, a = heapq.heappop(que)
        now += a
        if now > b:
            return False
    return True

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

Solution (Python):
import heapq

def solve():
    N = int(input())
    que = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(que, (-b, a))
    now = 10 ** 10
    while que:
        b, a = heapq.heappop(que)
        b = -b
        if now > b:
            now = b
        now -= a
        if now < 0:
            return False
    return True

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

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

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

tasks = sorted(tasks, key=lambda x: x[1])
time = 0
for task in tasks:
    time += task[0]
    if time > task[1]:
        print("No")
        exit()
print("Yes")

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

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

sorted_AB = sorted(AB, key=lambda x:(x[1], -x[0]))
worked = 0
for ab in sorted_AB:
  worked += ab[0]
  if worked > ab[1]:
    print('No')
    exit(0)

print('Yes')

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

for i in range(n):
  if t + tasks[i][0] > tasks[i][1]:
    print('No')
    exit()
  t += tasks[i][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])

time = 0

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

print("Yes")

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

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

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

print("Yes")

Solution (Python):
import numpy as np

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

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

A = [x[0] for x in AB_sort]
B = [x[1] for x in AB_sort]

A_cum = np.array(A).cumsum()

for i in range(N):
    if A_cum[i] > B[i]:
        print('No')
        exit()

print('Yes')

Solution (Python):
N=int(input())
l=[]
for _ in range(N):
    ab=list(map(int,input().split()))
    l.append(ab)
l.sort(key=lambda x:x[1])
time=0
flag=True
for i in range(N):
    time+=l[i][0]
    if time>l[i][1]:
        flag=False
        break
if flag==True:
    print('Yes')
else:
    print('No')

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

    time = 0
    for i in range(N):
        a, b = works[i]
        time += a
        if time > b:
            print('No')
            return
    print('Yes')

if __name__ == "__main__":
    main()

Solution (Python):


import sys

import heapq


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    """
    締切がはやい順に仕事を行う。
        全て完了できれば: Yes
        できなければ: No
    """
    n = input_int()
    hq = []
    for _ in range(n):
        a, b = input_int_list()
        heapq.heappush(hq, (b, a))
    t = 0
    while hq:
        b, a = heapq.heappop(hq)
        t += a
        if t > b:
            print("No")
            return
    print("Yes")
    return


if __name__ == "__main__":
    main()

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

limit2time = []

for i in range(N):
    time, limit = map(int, input().split())

    limit2time.append((limit, time))

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


cur = 0
for item in limit2time:
    
    key, time = item
    if cur + time > key:
        print("No")
        break
    cur += time
else:
    print("Yes")

Solution (Python):
time=0
n=int(input())
todo=[]*n

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

todo.sort()
d=True

for i in range(n):
  time += todo[i][1]
  if todo[i][0]<time:
    d=False
    break

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():

    lines = input()
    n = int(lines[0].strip())

    E = [list(map(int, lines[i].split())) for i in range(1, n+1)]
    E = sorted(E, key=lambda x: x[1])

    cur_t = 0

    for i in range(n):
        cur_t += E[i][0]
        if cur_t > E[i][1]:
            print('No')
            return

    print('Yes')

main()

Solution (Python):
N=int(input())
li=[]
ans="Yes"
t=0
for i in range(N):
    A,B=map(int,input().split())
    li.append([B,A])
li.sort()

for j in range(N):
    t+=li[j][1]
    if t<=li[j][0]:
        pass
    else:
        ans="No"
        
print(ans)

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

work = [[] for i in range(N)]

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

work.sort()
total = 0
for i in range(N):
    total += work[i][1]
    if total > work[i][0]:
        print('No')
        exit(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])
now=0
for a,b in ab:
  now+=a
  if now>b:
    print("No")
    exit()
print("Yes")

Solution (Python):
def main():
    point = 0
    ab = []
    for i in range(int(input())):
        t = list(map(int, input().split()))
        ab.append(t)
    ab.sort(key=lambda x: x[1])
    for i in range(len(ab)):
        point += ab[i][0]
        
        if point > ab[i][1]:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    main()

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

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

check = True
sum_A = 0
for j in range(N):
  sum_A += BA[j][1]
  if sum_A > BA[j][0]:
    check = False
    break
    
print("Yes" if check else "No")

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

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

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


n = inint()

wt = []

for i in range(n):
    a, b = inintm()
    wt.append([a,b])

wt = sorted(wt, reverse=True, key=lambda x: x[1])[::-1]

t = 0

for j in range(n):
    t += wt[j][0]
    if t > wt[j][1]:
        print("No")
        exit()

print("Yes")

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

Solution (Python):
if __name__ == "__main__":
    N = int(input())
    tasks = []
    for _ in range(N):
        a, b = map(int, input().split())
        tasks.append((b, a))
    tasks.sort()
    t = 0
    for b, a in tasks:
        if t + a > b:
            break
        t += a
    else:
        print("Yes")
        exit(0)
    print("No")

Solution (Python):
def main():
    N = int(input())
    A = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(tuple([b,a]))
    A.sort()
    total = 0
    for a, b in A:
        total+=b
        if a < total:
            print('No')
            return
    print('Yes')
main()

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

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

Solution (Python):
import numpy as np
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i],b[i]=map(int,input().split())

flag=True
sum=0
sorted_index=np.argsort(b)
for i in sorted_index:
  sum+=a[i]
  if sum>b[i]:
    flag=False
    break
    
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])
time = 0
ans = "Yes"
for i in range(n):
    time += ab[i][0]
    if time <= ab[i][1]:
        continue
    else:
        ans = "No"
        break
print(ans)

Solution (Python):

from collections import deque
from collections import Counter
from operator import itemgetter
from bisect import bisect_left, bisect
from decimal import *
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)


def main():
    n = int(input())
    arr = []
    for i in range(n):
        arr.append(list(map(int, input().split())))
    arr_sorted = sorted(arr, key=lambda x: x[1])

    now = 0

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline
al = [list(map(int, input().split())) for _ in range(int(input()))]
al = sorted(al, key=lambda x: x[1])
s = 0
for i, j in al:
    s += i
    if s > j:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


N = int(input())

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

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")
        sys.exit()

print("Yes")

Solution (Python):

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

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

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

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ab = [LI() for _ in range(n)]
ab.sort(key=itemgetter(1))
time = 0
for a, b in ab:
    time += a
    if time > b:
        print('No')
        quit()
print('Yes')

Solution (Python):
import itertools
n = int(input())
work_lst = []

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

work_lst.sort(key=lambda x: x[1])
work_acc = [i[0] for i in work_lst]
work_acc = itertools.accumulate(work_acc)
work_dead = [i[1] for i in work_lst]
for x, dead in zip(work_acc, work_dead):
    if x > dead:
        print("No")
        break
else:
    print("Yes")

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

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

time=0

for i in lst:
  time+=i[0]
  if time>i[1]:
    print('No')
    exit()
    
    
print('Yes')