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:
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2
# ここで分割を行う
 left = arr[:mid]
 right = arr[mid:]
# 再帰的に分割を行う
 left = merge_sort(left)
 right = merge_sort(right)
# returnが返ってきたら、結合を行い、結合したものを次に渡す
 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0
# ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
 while l_i < len(left) and r_i < len(right):
    # ここで=をつけることで安定性を保っている
  if left[l_i][1] <= right[r_i][1]:
   merged.append(left[l_i])
   l_i += 1
  else:
   merged.append(right[r_i])
   r_i += 1

# 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lsta=merge_sort(lst)
ans=0
t=0
for i in range(N):
 t+=lsta[i][0]
 if t>lsta[i][1]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Submission status: Accepted

Solution code:
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2
# ここで分割を行う
 left = arr[:mid]
 right = arr[mid:]
# 再帰的に分割を行う
 left = merge_sort(left)
 right = merge_sort(right)
# returnが返ってきたら、結合を行い、結合したものを次に渡す
 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0
# ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
 while l_i < len(left) and r_i < len(right):
    # ここで=をつけることで安定性を保っている
  if left[l_i][0] <= right[r_i][0]:
   merged.append(left[l_i])
   l_i += 1
  else:
   merged.append(right[r_i])
   r_i += 1

# 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
for i in range(N):
 A,B= map(int,input().split())
 lst[i]=[B,A]
lsta=merge_sort(lst)
ans=0
t=0
for i in range(N):
 t+=lsta[i][1]
 if t>lsta[i][0]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Submission status: Accepted

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

A = []

for i in range(N):
    A.append((data[i][1],data[i][0]))

A = sorted(A)

a = 0  #i番目にやった仕事の終了時間
for i in range(N):
    a += A[i][1]
    if a > A[i][0]:
        print('No')
        break
    else:
        continue
else:
    print('Yes')

Submission status: Accepted

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

t = 0
for i in range(n):
    t += l[i][0]
    if(t > l[i][1]):
        print('No')
        exit()
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(B, A)
C = sorted(C)
B, A = zip(*C)

ans = 1
t = 0
for i, j in zip(A, B):
    t += i
    if t <= j:
        continue
    else:
        print("No")
        ans = 0
        break
if ans:
    print("Yes")

Submission status: Accepted

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

#%%
ab = sorted(ab, key=lambda x: x[1])
flag = True

cost = 0
for a, b in ab:
    cost += a
    if cost > b:
        flag = False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
li = [] # AとBのリスト
x = 0
 
for i in range(n):
    li.append(list(map(int,input().split())))
li.sort(key=lambda x: x[1]) # Bの締め切りの早いものでソート
 
for i in range(n):
    x += li[i][0]
    if x > li[i][1]:
        print("No") # 締め切りの早いものから終わらせていき、終わらなかったらNo
        exit()
 
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(B, A)
C = sorted(C)
B, A = zip(*C)

ans = 1
t = 0
for i, j in zip(A, B):
    t += i
    if t <= j:
        continue
    else:
        print("No")
        ans = 0
        break
if ans:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
li = []
x = 0

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

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

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
works = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
result = True
cnt = 0
for a, b in works:
    cnt += a
    if cnt > b:
        result = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,task):
    t = 0
    task = sorted(task, key=itemgetter(1))
    for item in task:
        t += item[0]
        if item[1] < t:
            return "No"
    return "Yes"

n = ii()
task = mix(n)
print(main(n,task))

Submission status: Accepted

Solution code:
'''
ABC 131 D:Megalomania
Accepted    　:Yes
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :9分
WAの回数　     :0回
合計時間　　  　:9分
'''
import sys
input = sys.stdin.readline

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   # 締め切り時間をkey、作業時間をvalueにした辞書を作成
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      # print(deadline,time)
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer(N:int,dic:dict) -> str:
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def main():
   N = int(input())
   dic = {}
   # A = []
   # B = []
   for _ in range(N):
      a,b = map(int,input().split())
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
      # A.append(a)
      # B.append(b)
   print(modelAnswer(N,dic))
if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
'''
ABC 131 D:Megalomania
Accepted    　:Yes
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :9分
WAの回数　     :0回
合計時間　　  　:9分
'''

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   # 締め切り時間をkey、作業時間をvalueにした辞書を作成
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      # print(deadline,time)
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer(N:int,dic:dict) -> str:
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def main():
   N = int(input())
   dic = {}
   # A = []
   # B = []
   for _ in range(N):
      a,b = map(int,input().split())
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
      # A.append(a)
      # B.append(b)
   print(modelAnswer(N,dic))
if __name__ == '__main__':
   main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
from operator import itemgetter

def main():
    N = int(readline())
    AB = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print('No')
            return
        
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
from operator import itemgetter

def main():
    N = int(readline())
    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print('No')
            return
        
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
from operator import itemgetter

def main():
    N = int(readline())
    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        if t + a > b:
            print('No')
            return
        t += a
    
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

n=int(input())

a=defaultdict(int)
b=defaultdict(int)


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


bb=sorted(b.items(),key=lambda x:x[1])

sum=0
for k,v in bb:
    sum += a[k]
    if sum > v:print('No');exit()

print('Yes')

# n = int(input())
# d = [list(map(int,input().split())) for i in range(n)]
# d.sort(key=lambda x: x[1])
# ans = 'Yes'
# t = 0
# for i in d:
#     t += i[0]
#     if t>i[1]:ans='No'
# print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print("Yes")

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = [list(map(int,input().split())) for _ in range(N)]
arrA.sort(key = lambda x:x[1])
num = 0
for arr in arrA:
    num += arr[0]
    if num > arr[1]:
        print("No")
        exit()

print("Yes")
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

Solution code:
n = int(input())
work_ls = [0] * n
for i in range(n):
    a,b = map(int,input().split())
    work_ls[i] = [a,b]
work_ls.sort(key = lambda x:x[1])
time = 0
res = 'Yes'
for cost, dline in work_ls:
    time += cost
    if time > dline:
        res = 'No'
print(res)

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])
t=0
for i in range(n):
    t=t+ab[i][0]
    if t>ab[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

from operator import itemgetter
AB = sorted(AB, key=itemgetter(1))

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

Submission status: Accepted

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

from operator import itemgetter
AB = sorted(AB, key=itemgetter(1))

rt = 'Yes'
X = []
val = 0
for i in range(N):
    val += AB[i][0]
    X.append( [val, AB[i][1]] )
    if val > AB[i][1] :
        rt = 'No'
        break
print(rt)

Submission status: Accepted

Solution code:
N=int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(AB, key = lambda x: x[1])#締め切り時間が速いものからやる。貪欲法
time=0
c=0
for ab in AB:
  time+=ab[0]
  if time>ab[1]:
    print("No")
    c=1
    break
if c==0:
  print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
A=[[0,0] for i in range(n)]
for i in range(n):
  A[i][1],A[i][0]=map(int,input().split())
  
A.sort()
time=0
flg=True
for i in range(n):
  time+=A[i][1]
  if time>A[i][0]:
    flg=False
    
if flg:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N = int(input())
AB = []

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

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

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

Submission status: Accepted

Solution code:
import sys
n = int(input())

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

time = 0
for a, b in works:
    time += a
    if b < time:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

n = int(input())
now = 0
s = {}
for _ in range(n):
    a, b = map(int, input().split())
    if b in s:
        s[b] = s[b] + a
    else:
        s[b] = a
s = sorted(s.items())
for x in s:
    now += x[1]
    if now > x[0]:
        print('No')
        sys.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])

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

Submission status: Accepted

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
flag = True
sortedab = sorted(ab, key=lambda x:x[1])
cleartime = [0]*n
cleartime[0] = sortedab[0][0]
if cleartime[0] > sortedab[0][1]:
    flag = False
else:
    for i in range(1, n):
        cleartime[i] = cleartime[i-1] + sortedab[i][0]
        if cleartime[i] <= sortedab[i][1]:
            continue
        else:
            flag = False
            break
if flag:
    print("Yes")
else:
    print("No")

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])
t = 0
for a_b in A_B:
    t += a_b[0]
    if t > a_b[1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
task = []
for i in range(n):
  m = list(map(int,input().split()))
  m[0],m[1]=m[1],m[0]
  task.append(m)
task.sort()
K = 0
ans = 1
for i in range(n):
  K += task[i][1]
  if (K>task[i][0]):
    ans = 0
    break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n = int(input())
l = [[0, 0] for _ in range(n)]
ans = "Yes"
for i in range(n):
    a, b = map(int, input().split())
    l[i][0] = b
    l[i][1] = a
l.sort()
t = 0
for i in range(n):
    t += l[i][1]
    if t > l[i][0]:
        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 x: x[1])
temp=0
for i in ab:
    temp+=i[0]
    if temp>i[1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    s, t = map(int, input().split())
    a.append([s, t])
a = sorted(a, key=lambda x: x[1])
time = 0
flag = True
for i in range(n):
    time += a[i][0]
    if time > a[i][1]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

cnt = 0
for a, b in AB:
    if cnt + a <= b:
        cnt += a
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

def main():
    N = int(input())
    AB = sorted([[int(_) for _ in 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')
            break
    else:
        print('Yes')

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def D():
    n = int(input())
    t = [list(map(int, input().split()))[::-1] for _ in range(n)]
    t = sorted(t)
    time, result = 0, "Yes"
    for b, a in t:
        time += a
        if b < time:
            result = "No"
            break
    print(result)        
D()

Submission status: Accepted

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

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

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

dic = {}
B = []

for i in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if '{}'.format(b) in dic:
        dic['{}'.format(b)] += a
    else:
        dic['{}'.format(b)] = a

Bs = sorted(list(set(B)))

time = 0

for i, num in enumerate(Bs):
    time += dic['{}'.format(num)]
    if num < time:
        print('No')
        break

    if i == len(Bs)-1:
        print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    work = []  # due, duration
    for _ in range(N):
        a, b = map(int, input().split())
        work.append((b, -a))
    work.sort()

    now = 0
    for b, a in work:
        now = now - a
        if now > b:
            return "No"
    return "Yes"


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

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])
time = 0
ans = "Yes"
for a, b in ab:
    time += a
    if time > b:
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    task = []
    for _ in range(n):
        a, b = mi()
        task.append([a, b])
    task.sort(key=lambda x: x[1])
    t = max(task, key=lambda x: x[1])[1]
    while task:
        required_slot, end = task.pop()
        # time slot が時間軸の後ろ側へしシフトするのは許されない
        if t > end:
            t = end
        t -= required_slot
    print('No') if t < 0 else print('Yes')



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(N):
    A,B = map(int,input().split())
    L.append([B,A])
L = sorted(L)
t = 0
for i in range(N):
    t += L[i][1]
    if t > L[i][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
A = [None] * N
for i in range(N):
  A[i] = list(map(int,input().split()))

#s = sorted(A, key=itemgetter(0),reverse=True)
t = sorted(A, key=itemgetter(1))

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
A = [None] * N
for i in range(N):
  A[i] = list(map(int,input().split()))

s = sorted(A, key=itemgetter(0),reverse=True)
t = sorted(s, key=itemgetter(1))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
sorted_ab = sorted(ab, key=lambda AB: AB[1])
ans = 'Yes'
t = 0
for AB in sorted_ab:
  t += AB[0]
  if t > AB[1]:
    ans = 'No'
    break

print(ans)

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

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

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

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())

j_list = []
for _ in range(n):
    a, b = [int(x) for x in input().split()]
    j_list.append((a, b))
j_list.sort(key=itemgetter(1))

ans = "Yes"
t = 0
for a, b in j_list:
    t += a
    if t > b:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
#D
n = int(input())
work = []
for i in range(n):
    a,b = map(int,input().split())
    work.append([a,b])
#締め切りの早さでソート
work.sort(key=lambda x:x[1])

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N = int(input())
li = [0]*N
for i in range(N):
    A,B = inputlist()
    li[i] = [B,A]
li.sort()
suma = li[0][1]
if suma > li[0][0]:
    print("No")
    exit()
for i in range(1,N):
    suma += li[i][1]
    if suma > li[i][0]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
N = int(input())
work = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
work_soted = sorted(work, key=lambda x:(x[1], -x[0]))

bool = True
time = 0
for i in range(N):
    time += work_soted[i][0]
    if time > work_soted[i][1]:
        bool = False
        break
    
if bool:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
l = []
ans = "Yes"
for i in range(n):
    a, b = map(int, input().split())
    l.append([b, a])
l.sort(reverse=True)
tmp = l[0][0]
for i in range(n):
    if tmp > l[i][0]:
        tmp = l[i][0]
    tmp -= l[i][1]
    if tmp < 0:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ab = [[0]*2 for i in range(n)]

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

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

ws = 0

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

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i],b[i]=map(int,input().split())
  
b,a=zip(*sorted(zip(b,a)))
sum=0

for i in range(n):
  sum+=a[i]
  if sum>b[i]:
    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])
t = 0
flag = True
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

ABs.sort()

t = 0
for tTo, tm in ABs:
    t += tm
    if tTo < t:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n,*pl=map(int,open(0).read().split())
l=[[pl[i],pl[i+1]] for i in range(0,n*2,2)]
l.sort(key=lambda x:x[1])
t=0#time
p=True
for i,j in l:
    t+=i
    if t>j:
        p=False
        print('No')
        break
if p:
    print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
l=list()
for i in range(n):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:x[1])
t=0#time
p=True
for i,j in l:
    t+=i
    if t>j:
        p=False
        print('No')
        break
if p:
    print('Yes')