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



Sample input:
5
2 4
1 9
1 8
4 9
3 12


Sample output:
Yes

Submission status: Accepted

Solution code:
#import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

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

lst = sorted(AB, key=lambda x: x[1], reverse=True)
deadline = lst[0][1]

for i in range(N):
  if lst[i][1] < deadline:
    deadline = lst[i][1] - lst[i][0]
  else:
    deadline = deadline - lst[i][0]
  if deadline < 0:
    print('No')
    exit()
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
import heapq

ans = 'Yes'
N = int(input())

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

d.sort(key=lambda x:x[1])
T = 0
for i in range(N):
    T += d[i][0]
    if T > d[i][1]:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    X = [list(map(int,input().split())) for _ in range(N)]
    X.sort(key = lambda x:x[1])
    time = 0

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

        if time > X[i][1]:
            print('No')
            return

    print('Yes')

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

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

print("Yes")

Submission status: Accepted

Solution code:
import sys
n = int(input())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b])
ab = sorted(ab,key=lambda x:x[1])
limit = 0
for i in range(n):
    limit += ab[i][0]
    if limit > ab[i][1]:
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
ba = [0 for _ in range(n)]
for i in range(n):
    ba[i] = list(map(int, input().split()))[::-1]
ba_sort = sorted(ba)
t = 0
for i in range(n):
    t += ba_sort[i][1]
    if t > ba_sort[i][0]:
        print('No')
        exit(0)
print("Yes")

Submission status: Accepted

Solution code:
def main():
    n = int(input())

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

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

    now = 0
    for t, deadline in tasks:
        now += t
        if deadline < now:
            print("No")
            return

    print("Yes")

main()

Submission status: Accepted

Solution code:
N, *D = map(int, open(0).read().split())
D = list(zip(*[iter(D)]*2))
D = sorted(D, key=lambda x:x[1])
t = 0
f = True
for d in D:
  if t + d[0] <= d[1]:
    t += d[0]
  else:
    f = False
    break
print('Yes' if f else 'No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n = ii()
arr=llint(n)
arr.sort(key=lambda x: x[1])
cnt=0
chk=True
for i,j in arr:
    if cnt + i <=j:
        cnt +=i
    else:
        chk=False
if chk:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
l_2d = []
for i in range(N):
  l_2d.append(list(map(int,input().split())))
l_2d.sort(key=lambda x: x[1], reverse=False)
A=0
ANS='Yes'
for l in l_2d:
  A += l[0]
  if l[1] < A:
    ANS = 'No'
    break
print(ANS)

Submission status: Accepted

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

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

Submission status: Accepted

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

AB = zip(B, A)
AB.sort()
x = 10**9
for b, a in AB[::-1]:
  x = min(x, b)-a
print "Yes" if x>=0 else "No"

Submission status: Accepted

Solution code:
N = int(input())
task = []
for _ in range(N):
    A,B = map(int,input().split())
    task.append([A,B])
task.sort(key=lambda task:task[1])

time = 0
ans = "Yes"
for i in range(N):
    A = task[i][0]; B = task[i][1]
    if time + A <= B:
        time += A
    else:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
import heapq
DEADLINE = 0
REQTIME = 1

ans = "Yes"

N = int(input())
min_heap = []
for i in range(N):
    job = [int(x) for x in input().split()]
    job = tuple((job[1], job[0]))
    heapq.heappush(min_heap, job) # 締め切りでmin heap

t = 0 # 現在時刻
for _ in range(N): # 取り出して仕事をする
    job = heapq.heappop(min_heap)
    t += job[REQTIME]
    if t > job[DEADLINE]:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ba_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append([ba_tmp[1], ba_tmp[0]])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
ba_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append(ba_tmp[::-1])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
AB = []
for s in inputs[1:]:
    a, b = map(int, s.split())
    AB.append((a, b))
AB.sort(key=lambda x: x[1])
s = 0
for a, b in AB:
    s += a
    if s > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
tasks = []
for i in range(N):
    D = list(map(int,input().split()))
    tasks.append(D)
tasks.sort(key=lambda x:x[1])
time = 0
total = 0
for i in range(N):
    total += tasks[i][0]
    if total>tasks[i][1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

now=0
for job in S:
    now+=job[0]

    if now > job[1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
jobs = []
for _ in range(int(input())):
    a, b = [int(i) for i in input().split()]
    jobs.append((a, b))

jobs.sort(key=lambda j: j[1])
curr_jour = 0

can = True
for j in jobs:
    curr_jour += j[0]
    if curr_jour > j[1]:
        can = False
        break

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

AB.sort(key=lambda x:x[1])
t=0
for ab in AB:
  a=ab[0]
  b=ab[1]
  t+=a
  if b<t:
    print("No");exit()
print("Yes")

Submission status: Accepted

Solution code:
def main(n, a_b):
    a_b.sort(key=lambda a_b: a_b[1])

    t = 0
    for a, b in a_b:
        t += a
        if t > b:
            print('No')
            return

    print('Yes')


if __name__ == "__main__":
    n = int(input())
    a_b = [list(map(int, input().split())) for _ in range(n)]

    main(n, a_b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
L=[]
for i in range(N):
    a,b=map(int,input().split())
    L.append([a,b])
#print(L)
L.sort(key=lambda x: x[1])
#print(L)

t=0
ans=0
for i in range(N):
    if t+L[i][0]<=L[i][1]:
        ans+=1
        t+=L[i][0]

if ans==N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
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])

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

print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
tasks=[]
for i in range(0,n):
    a,b=map(int,input().split())
    tasks.append((b,a))
tasks.sort()
now=0
fail=0
for i in tasks:
    b=i[0]
    a=i[1]
    now+=a
    if now>b:
        fail=1
if fail:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
t = 0
ans = "Yes"
tasks = []
for i in range(N):
  tasks.append(list(map(int, input().split())))
tasks.sort(key=lambda task: task[1])
for task in tasks:
  t += task[0]
  if task[1] < t:
    ans = "No"
    break
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
N = int(input())
AB = []

for i in range(N):
  a, b = map(int, input().split())
  heappush(AB, (b, a))


current = 0

for i in list(range(N)):
  deadline, cost = heappop(AB)

  if current + cost > deadline: # 締め切り時間を過ぎてしまっているとき
    print("No")
    exit()
  
  current += cost

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = [
    list(map(int, input().split())) for i in range(n)
]
works = sorted(w, key=lambda x: x[1])
time = 0
ans = "Yes"
for i in range(n):
    time += works[i][0]
    if time <= works[i][1]:
        continue
    else:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
AB=[list(map(int,input().split())) for i in range(n)]
AB.sort(key=lambda A:A[1])
flag=0
cnt=0
for i in range(n):
    cnt+=AB[i][0]
    if cnt>AB[i][1]:
        flag=1
print('Yes' if flag==0 else 'No')

Submission status: Accepted

Solution code:
n = int(input())
tasks = []
for i in range(n):
  a = list(map(int, input().split()))
  tasks.append(a)
tasks.sort(key=lambda x: x[1])
sum = 0
answer = True
for i in range(n):
  sum += tasks[i][0]
  if sum <= tasks[i][1]:
    continue
  else:
    answer = False
    break
if answer:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n = int(input())
ls = [[int(_) for _ in input().split()] for _ in range(n)]

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

t = 0

for i in range(n):
    t += ls[i][0]
    if t > ls[i][1]:
        print("No")
        break
    elif i == n - 1:
        print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append((a,b))
A.sort(key=lambda x:x[1])
tmp=0
cnt=0
for x,y in A:
    tmp+=x
    if tmp<=y:
        cnt+=1
if cnt==n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
data = [list(map(int, input().strip().split())) for _ in range(n)]

data = sorted(data, key=lambda d: d[1])

work_time = 0
impossible = False
for a, b in data:
    deadline = b
    work_time += a
    if work_time > b:
        impossible = True
        break

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

Submission status: Accepted

Solution code:
def main():
    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")
            return 0

    print("Yes")
    return 0

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

i = 0
ab = []
while i < n:
    a, b = map(int, input().split())
    ab.append((a, b)) 
    i += 1

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

i = 0
ans = 'Yes'
days = 0
while i < n:
    days += ab[i][0]
    if days > ab[i][1]:
        ans = 'No'
        break
    i += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ab =[list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda l: l[1])
t = 0
out = 'Yes'
for i in range(n):
  t += ab[i][0]
  if t > ab[i][1]:
    out = 'No'
    break
print(out)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [list(map(int, input().split())) for i in range(n)]
    s = sorted(a, key=lambda x:x[1])

    t = 0
    for i in range(n):
        t += s[i][0]
        if t > s[i][1]:
            print('No')
            return
    print('Yes')
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    flag = True
    tascs = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        tmp = [a, b]
        tascs.append(tuple(tmp))
    tascs.sort(key=lambda x: x[1])
    passed_time = 0
    for tasc in tascs:
        passed_time += tasc[0]
        if passed_time > tasc[1]:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a=[]
time=0
ans=True

for i in range(n):
    s,p=map(int,input().split())
    a+=[[s, p] ]
    

import operator as op
a.sort(key = op.itemgetter(1))

for i  in range(n):
    time+=a[i][0]
    if(time>a[i][1]):
        ans=False
        break
    
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#ABC131D
n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
l=sorted(l,key=lambda x:x[1])
deadline=0
tmp=0
for i in range(n):
    tmp=l[i][1]
    deadline+=l[i][0]
    if tmp<deadline:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
Wo=[list(map(int,input().split())) for i in range(n)]
Wo.sort(key=lambda x:x[1])

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

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

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
def run_length_encode(s):
    count = 1
    code = []
    target = s[0]
    for i in range(1, len(s)):
        if target == s[i]: count += 1
        else:
            code.append((target, count))
            target = s[i]
            count = 1
    code.append((target, count))
    return code

N = iin()
AB = sorted([iln() for _ in range(N)], key=lambda x:x[1])

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
ab = [list(map(int,input().split())) for _ in range(N)]
ab = sorted(ab, key = lambda x:x[1],reverse=False)
deadline = 0 #sum(ab[:][0])
for i in range(N):
    a = ab[i][0]
    b = ab[i][1]
    deadline += a
    if deadline > b:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
BA=[[0,0] for _ in range(N)]

for i in range(N):
    BA[i][1],BA[i][0]=map(int,input().split())
BA.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

time = 0
for deadline, task_time in deadlines:
    if time + task_time <= deadline:
        time += task_time
    else:
        time = None
        break
print('Yes' if time is not None else 'No')

Submission status: Accepted

Solution code:
from fractions import Fraction
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
AB=sorted(AB,key=lambda x:x[1])
time=0
for a,b in AB:
    time+=a
    if time>b:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
AB = [[i for i in map(int,input().split())] for j in range(N)]
AB.sort(key=lambda x:x[1])

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

Submission status: Accepted

Solution code:
n = int(input())
x = []
for i in range(n):
  x.append([int(i) for i in input().split()])
x.sort(key=lambda a: a[1])
t = 0
for i in range(n):
  t += x[i][0]
  if t > x[i][1]:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

Solution code:
N = int(input())

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

t = 0

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

# print(AB)
fa, fb = AB[0][0], AB[0][1]
t = fb - fa
for a, b in AB[1:]:
    if b <= t:
        t = b
    t -= a
    # print(t)

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

Submission status: Accepted

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

heapq.heapify(tasks)

ans = "Yes"
time = 0
while len(tasks) > 0 :
    task = heapq.heappop(tasks)
    time += task[1]

    if task[0] < time:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = list(map(int, input().split()))
asort = sorted(a, key=lambda x: x[1])

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
ab = sorted([tuple(map(int,input().split())) for i in range(n)], key = itemgetter(1))
time = 0
for i in range(n):
    time += ab[i][0]
    if time > ab[i][1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

a_list = []
b_list = []
t = []
for i in range(n):
  a, b = map(int, input().split())
  t.append({"time": a, "limit": b})
  a_list.append(a)
  b_list.append(b)
  
s = sorted(t, key=lambda x: x["limit"])

time = 0
for ss in s:
  time += ss['time']
  if time > ss['limit']:
    print('No')
    exit(0)

print('Yes')

Submission status: Accepted

Solution code:
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()
ab = []
for _ in range(n):
    abi = na()
    ab.append(abi)

ab.sort(key=lambda x:x[1])
t = 0
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

Solution code:
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect
import heapq


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    N = get_input(int)
    AB = []
    for _ in range(N):
        A, B = get_inputs(int)
        AB.append((A, B))
    AB.sort(key=lambda x: x[1])

    cur_time = 0
    for A, B in AB:
        cur_time += A
        if cur_time > B:
            print('No')
            return
    print('Yes')
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter
N=int(input())
tasks=[list(map(int,input().split())) for _ in range(N)]
tasks.sort(key=itemgetter(1))
t=0
for w,l in tasks:
    if t+w>l:
        print('No')
        exit()
    t+=w
print('Yes')

Submission status: Accepted

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


def f():
    time = 0
    for task in tasks:
        time += task[0]
        if time > task[1]:
            return "No"
    
    return "Yes"

print(f())

Submission status: Accepted

Solution code:
import heapq
import sys
input = sys.stdin.readline

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

  pq = []

  for ab in abs:
    a,b = ab[0],ab[1]
    heapq.heappush(pq, tuple([b,a]))

  dl = 0
  tc = 0

  ans = "Yes"

  for i in range(n):
    ba = heapq.heappop(pq)
    dl = ba[0]
    tc += ba[1]
    if dl < tc:
      ans = "No"
      break
  print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import heapq

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

  pq = []

  for ab in abs:
    a,b = ab[0],ab[1]
    heapq.heappush(pq, tuple([b,a]))

  dl = 0
  tc = 0

  ans = "Yes"

  for i in range(n):
    ba = heapq.heappop(pq)
    dl = ba[0]
    tc += ba[1]
    if dl < tc:
      ans = "No"
      break
  print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import heapq

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

pq = []

for ab in abs:
  a,b = ab[0],ab[1]
  heapq.heappush(pq, tuple([b,a]))
  
dl = 0
tc = 0

ans = "Yes"

for i in range(n):
  ba = heapq.heappop(pq)
  dl = ba[0]
  tc += ba[1]
  if dl < tc:
    ans = "No"
    break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A_B = [list(map(int, input().split())) for _ in range(N)]
A_B.sort(key=lambda x: x[1])
count = 0
for i in range(N):
    if count + A_B[i][0] <= A_B[i][1]:
        count += A_B[i][0]
        continue
    print("No")
    break
else:
    print("Yes")

Submission status: Accepted

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

C = zip(A, B)

C = sorted(C)

A, B = zip(*C)

A = list(A)
B = list(B)

A.reverse()
B.reverse()

C = zip(B, A)

C = sorted(C)

B, A = zip(*C)

A = list(A)
B = list(B)

for i in range(N):
    if i!=0:
        A[i]=A[i-1]+A[i]

flag = 0

for i in range(N):
    if A[i]>B[i]:
        flag = 1

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

Submission status: Accepted

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

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

t = 0
ans = 'Yes'
for i in range(N):
    t += do[i][0]
    if t > do[i][1]:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
work = [list(map(int,input().split())) for _ in range(N)]
work.sort(key=lambda x:x[1])
Time = 0
ans = 'Yes'
for i in range(N):
  Time += work[i][0]
  if Time > work[i][1]:
    ans = 'No'
    break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

W=np.array(tmp)
ind = np.argsort(W[:,1])
W=W[ind,:]

current_time =0
for iw in W:
    current_time += iw[0]
    if current_time > iw[1]:
        print("No")
        exit()

print("Yes")
exit()

Submission status: Accepted

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