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:
n = int(input())
li = [list(map(int,input().split())) for i in range(n)]

li.sort(key=lambda x: x[1])
limit = 0
asum = 0
output = 'Yes'
for i in range(n):
  limit = li[i][1]
  asum += li[i][0]
  if asum > limit:
    output = 'No'
    break

print(output)

Submission status: Accepted

Solution code:
import numpy
frag=True
n=int(input())
t=[list(map(int,input().split())) for _ in range(n)]
t=sorted(t,key=lambda x:x[1])
a=[t[i][0] for i in range(n)]
b=[t[i][1] for i in range(n)]
ar=list(numpy.cumsum(a))
for i in range(n):
  if ar[i] > b[i]:
    frag=False
if frag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n = int(input())

ab    = []
st_ab = []
a_l   = []
b_l   = []

wt_sum = 0
for i in range(n):
  a,b = map(int,input().split())
  ab.append([a,b])
  a_l.append(a)
  b_l.append(b)
  wt_sum += a

if wt_sum > max(b_l):
  print("No")
  exit()

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

wt_sum = 0

a,b = st_ab[0]

for i in range(n):
  a,b = st_ab[i]
  wt_sum += a

  if wt_sum > b:
    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])

ans = "Yes"
worktime = 0
for i in range(N):
    worktime += AB[i][0]
    if worktime > AB[i][1]:
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
# 2019/06/22
# AtCoder Beginner Contest 131 - D

from operator import itemgetter

# Input
n = int(input())
tlist = list()

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

tlist.sort(key=itemgetter(1))

etime = 0
ans = "Yes"
for i in range(n):
    etime += tlist[i][0]
    if etime > tlist[i][1]:
        ans = "No"

# Output
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

B = sorted(A, key = lambda x:x[1])
task = 0
time_1 = 0
flag = 0

for i in range(N):
    task += B[i][0]
    time_1 = B[i][1]

    if task <= time_1:
        pass
    else:
        flag = 1

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    work = []
    time=0
    for i in range(N):
        a,b = map(int,input().rstrip().split(' '))
        ob = {'A': a,'B':b}
        work.append(ob)
    work = sorted(work,key = lambda x: x['B'])
    for w in work:
        time += w['A']
        if time > w['B']:
            print('No')
            return 0
    print('Yes')

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
result = "Yes"


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

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

s = 0

for i in range(N):
    if ls[i][0] > ls[i][1]:
        result = "No"
        break
    s += ls[i][0]
    if s > ls[i][1]:
        result = "No"
        break

print(result)

Submission status: Accepted

Solution code:
N = int(input())
AB = []
for n in range(N):
    AB.append(list(map(int,input().split())))
AB = sorted(AB, key=lambda x: (x[1],x[0]))
time = 0
result = True
for n in range(N):
    if AB[n][1] < time + AB[n][0]:
        result = False
        break
    else:
        time += AB[n][0]
print("Yes") if result else print("No")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

now = 0

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

Submission status: Accepted

Solution code:
N = int(input())

AB = []

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



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

on_time = True

time = 0
for ab in AB:
    a = ab[0]
    b = ab[1]

    time += a

    if time > b:
        on_time = False

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

Submission status: Accepted

Solution code:
N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
sortedjobs = list(sorted(jobs, key = lambda x: x[1]))
tott = 0
flag = False
for A, B in sortedjobs:
    tott += A
    if tott > B:
        flag = True
if flag:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# coding: utf-8


N=int(input())
data=[]
for i in range(N):
    text = input()
    data.append((int(text.split()[0]), int(text.split()[1])))

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


imakonojikan=0

for i in range(len(data)):
    imakonojikan+=data[i][0]
    if data[i][1]<imakonojikan :
        print('No')
        exit(0)

print('Yes')


exit(0)

Submission status: Accepted

Solution code:
N = int(input())
WS = [[int(i) for i in input().split()] for i in range(N)]
WS = sorted(WS, key=lambda x: x[1])
total = 0
for w in WS:
    total += w[0]
    if total > w[1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#a, b, c, d = (int(i) for i in input().split())  
#W = [int(i) for i in input().split()] 

N= (int(input()))
flag = 0
A_list = []
B_list = []
AB_list = []
for i in range(N):
    a,b= (int(j) for j in input().split())  
    A_list.append(a)
    B_list.append(b)
    AB_list.append([a,b])
    pass
AB_list = sorted(AB_list, key=lambda x: x[1])
#print(AB_list)
now = 0
for ab in AB_list:
   now += ab[0]
   if ab[1] < now:
       flag = 1
       break
   pass
if flag == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:

n = int(input())

list_ba = [] 

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

list_ba.sort()

w = 0
rtn = "Yes"
for s in list_ba:
    w += s[1]
    if (w > s[0]):
        rtn = "No"
        break

print(rtn)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[3]:


import numpy as np


# In[42]:


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


# In[43]:


data = np.array(data)


# In[44]:


sorted_data = data[np.argsort(data[:, 1])]
cumsum_data = np.cumsum(sorted_data[:,0])


# In[45]:


flag = 0
for i in range(N):
    if cumsum_data[i] > sorted_data[i, 1]:
        flag = 1
        break

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


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())

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

# sort ascending by deadline,worktime
works.sort(key=lambda x: (x[1], x[0]))

now = 0 
for work in works:
    now += work[0]
    deadline = work[1]
    if now > deadline:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys

n = int(input())

ab = []

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

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

sumA = 0

available = True

for a, b in ab :
    sumA += a
    if sumA>b:
        available = False
        break

if available == False:
    print('No')
else :
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
tasks = [tuple(map(int, input().split())) for _ in range(N)]
tasks.sort(key = lambda i:i[1])
time = 0
for a, b in tasks:
    time += a
    if time > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
li = list(list(map(int, input().split())) for i in range(n))

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import numpy as np

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

b_sort_index = np.argsort(b_list)
time = 0
for i in b_sort_index:
    time += a_list[i]
    if time > b_list[i]:
        print('No')
        exit(0)
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
tl=[]
for inp in range(n):
    ab = input().split()
    tl.append((int(ab[1]),int(ab[0])))

#print(tl)

tl.sort()

#print(tl)

sums=0
for tup in tl:
    sums+=tup[1]
    if tup[0]<sums:
        #print(sums,tup[0])
        ans="No"
        break
else:
    ans="Yes"

print(ans)

Submission status: Accepted

Solution code:
import sys

n = int(input())
task_dead = [[0,0]]*(n+1)

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

stack = [0]*(n+1)
for i,task in enumerate(task_dead):
    if i!=0:
        stack[i] = stack[i-1]+task[0]
        if stack[i] > task[1]:
            print('No')
            sys.exit()
print('Yes')

Submission status: Accepted

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

time = 0

for i,j in task:
  time += i
  if time > j:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
#ab = [input().split() for l in range(n)]

ab = [[int(i) for i in input().split()] for _ in range(n)]

#ab = list(map(int, ab))

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

time = 0

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

print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
num = int(input())
ab = []
for i in range(num):
    a,b = map(int,input().split())
    tmp = [b,a]
    ab.append(tmp)

ab_sorted = sorted(ab,reverse = True)

f = True
next_st = ab_sorted[0][0]
for b,a in ab_sorted:
    if next_st < 0:
        f = False
        break
    elif next_st > b:
        next_st = b-a
    else:
        next_st = next_st-a
    if next_st<0:
        f = False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
l =[[0]*2 for i in range(n)]
checker = 0
a_ = 0
for i in range(n):
    a,b = map(int, input().split())
    l[i][1] = a
    l[i][0] = b

l = sorted(l)

for i in range(n):
    a_ = a_ + l[i][1]
    if a_ > l[i][0]:
        checker = 1
        break

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter


fin = sys.stdin.readline
N = int(fin())
ab_list = [[int(elem) for elem in fin().split()] for _ in range(N)]

ab_list = sorted(ab_list, key=itemgetter(1, 0))

current_time = 0
result = True
for ab in ab_list:
    a, b = ab
    current_time += a
    if current_time > b:
        result = False
        break
if result:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n =  int(input())

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

s = 0
y = 0
for i in range(n):
  s += x[i][0]
  if s > x[i][1]:
    y = 1
    print("No")
    break
if y == 0:
  print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
N=int(input())
jobs=[]
for _ in range(N):
    temp=list(map(lambda x:int(x),input().split()))
    jobs.append((temp[0],temp[1]))

jobs_temp=sorted(jobs,key=itemgetter(0))
jobs_sorted=sorted(jobs,key=itemgetter(1))
now=0
result="No"
for job in jobs_sorted:
    now+=job[0]
    if now>job[1]:
        break
else:
    result="Yes"

print(result)

Submission status: Accepted

Solution code:
N = int(input())
a = [[int(i) for i in input().split()] for j in range(N)]

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

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

print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=itemgetter(1,0))
time=0
ans='Yes'
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())
tasks = [list(map(int, input().split())) for i in range(n)]
sorted_t = sorted(tasks, key=lambda x: x[1])

res = 'Yes'
times = 0

for i in range(n):
  times += sorted_t[i][0]
  if times > sorted_t[i][1]:
    res = 'No'
    break

print(res)

Submission status: Accepted

Solution code:
n=int(input())
i=0
s=[]
a=[]
d=[]
while i!=n:
    a=list(map(int,input().split()))
    d.append(a[1])
    d.append(a[0])

    s.append(d)
    d=[]
    i+=1

s.sort()
#print(s)

ans=0
i=0
x=0
while i!=n:
    ans+=s[i][1]
    if ans>s[i][0]:
        x=1
        break
    i+=1
if x==1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
job = []
for i in range(n) :
	a,b = map(int, input().split())
	job.append([a,b])
job = sorted(job, key=lambda job: job[1])

time = 0
b = True
for i in range(len(job)) :
	time += job[i][0]
	if (time > job[i][1]) : b = False
if (b) : print("Yes")
else : print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#S = list(input())
	#A,B,C,D = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

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

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

	time = 0
	for i, val in enumerate(AB):
		a,b = val
		time += a
		if time > b:
			print("No")
			sys.exit()

	print("Yes")




if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
n = int(input())

ba = []

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

ba.sort()
totala = 0
totalb = 0

flag = True
for b, a in ba:
    totala += a
    totalb = b
    if totala > totalb:
        flag = False
        break

print('Yes' if flag 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])

for i in range(1,N):
    AB[i][0]+=AB[i-1][0]

s=0

for i in range(N):
    if AB[i][0]>AB[i][1]:
        s=1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

cnt = 0
flag = True
for i in range(N):
    #cnt += L[0][i]
#    print(L[i][0])
    cnt += L[i][0]
    #if cnt <= L[i][1]:
    if cnt > L[i][1]:
        flag = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())

List = list(list(map(int, input().split())) for i in range(N))

# print(List)

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

# print(List)

S = 0
for j in range(N):
    S += List[j][0]
    if(S > List[j][1]):
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
BAs = {}
for i in range(N):
    A, B = map(int, input().split())
    if not B in BAs:
        BAs[B] = A
    else:
        BAs[B] += A
BAs = sorted(BAs.items())
Bs, As = map(list, zip(*BAs))
for i in range(len(BAs) - 1):
    if As[i] > Bs[i]:
        print('No')
        exit()
    As[i + 1] += As[i]
if As[len(BAs) - 1] > Bs[len(BAs) - 1]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
num = int(input())

times = []
limits = []
for i in range(num):
	line = input().split(' ')
	times.append(int(line[0]))
	limits.append(int(line[1]))

time_limit = zip(limits, times)
test = sorted(time_limit)

times, limits = [], []
for limit, time in test:
	times.append(int(time))
	limits.append(int(limit))

now = 0
judge = True

for time, limit in zip(times, limits):
	now += time
	if now > limit:
		judge = False
		print('No')
		break

if judge:
	print('Yes')

Submission status: Accepted

Solution code:
import sys

def sort_nested_list(nested_list):
    nested_list.sort(key = lambda  x: x[1])
    return nested_list

N = int(input())

jobs = [list(map(int, input().split())) for _ in range(N)]
jobs = sort_nested_list(jobs)
time = 0

for job in jobs:
    hours, deadline = job[0], job[1]
    
    time += hours
    
    if time > deadline:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007


if __name__ == "__main__":
    n = int(sys.stdin.readline())
    l = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
    l = sorted(l,key=lambda l:l[1])
    t = 0
    for e in l:
        t += e[0]
        if t > e[1]:
            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])

judge=True
time=0

for i in range(n):
        time+=ab[i][0]
        if time>ab[i][1]:
                judge=False
                break

if judge:
        print("Yes")
else:
        print("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], x[0]))
s = 0
for t in AB:
    s += t[0]
    if (s > t[1]):
        print('No')
        quit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
Alist = []
Blist = []
cost = 0
for i in range(N):
    A, B = map(int, input().split())
    Alist.append(A)
    Blist.append(B)
    
k = zip(Blist, Alist)
q = sorted(k)
for i in range(N):
    cost += q[i][1]
    if cost > q[i][0]:
        print("No")
        break
    if i == N-1:
        print("Yes")

Submission status: Accepted

Solution code:
import sys

N = int(input())
tasks = []
lines = sys.stdin.readlines()
for line in lines:
    temp = [int(i) for i in line.split()]
    #tasks.append((temp[0], temp[1] - temp[0], temp[1]))
    tasks.append(tuple(temp))

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

for t in tasks:
    time += t[0]
    if time > t[1]:
        print('No')
        sys.exit(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][0],a[i][1]=map(int,input().split())
a.sort(key=lambda x:x[1])
sa=0
sb=0
count=0
for i in range(n):
    sa+=a[i][0]
    sb=a[i][1]
    if sa>sb:
        print("No")
        break
    else:
        count+=1
if count==n:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
N=int(input())
listAB=[]
for i in range(N):
  A,B=map(int,input().split())
  listAB+=[[B,A]]  
listAB.sort()
sumA=listAB[0][1]
for i in range(N-1):
  if listAB[i][0]<sumA:
    print("No")
    sys.exit()
  sumA+=listAB[i+1][1]
if listAB[N-1][0]<sumA:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

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

input = lambda: stdin.readline()
main()

Submission status: Accepted

Solution code:
import sys

N=int(input())
A=[[0]*2 for i in range(N)]

for i in range(N):
    A[i][0],A[i][1]= map(int,input().split())
sortsecond=lambda val:val[1]

A.sort(key=sortsecond)
sum=0
for i in range(N):
    sum+=A[i][0]
    if sum>A[i][1]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
def dec(X, d):
    X[1] -= d
    return X


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

task.sort(key=lambda x: x[1])
time = 0
for i in range(N):
    time += task[i][0]
    if time > task[i][1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
ba=[]
for i in range(n):
  c,d=map(int,input().split())
  ba.append([d,c])
ba.sort(key=lambda x:(x[0],-x[1]))
time=0
ans="Yes"
for i in range(n):
  time+=ba[i][1]
  if time<=ba[i][0]:
    continue
  else:
    """print("i",i)"""
    ans="No"
    break
print(ans)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
A_B = [list(map(int,input().split())) for i in range(N)]
A_B = sorted(A_B,key=itemgetter(1))
#print(A_B)
s=0
for a_b in A_B:
  s+=a_b[0]
  lim = a_b[1]
  if s > lim:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    n = int(input())
    ab = [list(map(int, stdin.readline().split())) for i in range(n)]
    ab.sort(key=lambda x:x[1])
    now = 0
    cnt = 0

    for a, b in ab:
        now += a
        if now > b: break
    else:
        print("Yes")
        return 0
    print("No")


if __name__=="__main__": main()

Submission status: Accepted

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

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

sumab = 0
flag = True
for ab in AB:
    sumab += ab[0]
    if sumab > ab[1]:
        flag = False
        break

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
lab = [0]*n
for i in range(n):
  a,b = map(int,input().split())
  lab[i] = [b,a]

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

Submission status: Accepted

Solution code:
import fractions
import sys

input = sys.stdin.readline

n = int(input())

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

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

flag = True
current_cost = 0
for item in list_dayo:
    current_cost += item[0]
    if current_cost > item[1]:
        flag = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())
table = []
for _ in range(N):
    a,b = map(int, input().split())
    if a > b:
        print('No')
        exit()
    table.append((a,b))

table = sorted(table, key = lambda x:x[1])
time = 0
for i in range(N):
    a, b = table[i]
    if time > b - a:
        print('No')
        exit()
    time += a
print('Yes')

Submission status: Accepted

Solution code:
# 複数行のスペース区切りの文字列をリストに
n = int(input())
e = [[int(i) for i in input().split()] for i in range(n)]

e = sorted(e, key=lambda x: x[1])
t=0
flg=0
for i in range(n):
    t+=e[i][0]
#     print(t,e[i][1])
    if(t>e[i][1]):
        flg=1
if flg==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

nda = np.array(ab)
nda_sort = nda[np.argsort(nda[:, 1])]
# print(nda_sort)

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
n=int(sys.stdin.readline())
task=[]
ans="Yes"
for i in range(n):
    task.append(list(map(int,sys.stdin.readline().split())))
task.sort(key=itemgetter(1))
ryou=0
for i in task:
    ryou+=i[0]
    if i[1]<ryou:
        ans="No"
        break
print(ans)

Submission status: Accepted

Solution code:

N = int(input())

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

works_info_lst.sort()

A_sum = 0
def judge(works_info_lst, A_sum, N):
    for i in range(N):
        A_sum += works_info_lst[i][1]
        if A_sum > works_info_lst[i][0]:
            return False
    return True

if judge(works_info_lst, A_sum, N):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

def solve(n, tasks):
    tasks.sort()
    #pprint(tasks)
    spent = 0
    for limit, time in tasks:
        spent += time
        if spent > limit:
            return 'No'

    return 'Yes'

if __name__ == '__main__':

    tasks = []
    n = int(sys.stdin.readline().strip())
    for _ in range(n):
        a, b = map(int, sys.stdin.readline().strip().split(" "))
        tasks.append((b, a))

    print solve(n, tasks)

Submission status: Accepted

Solution code:
N = int(input())
job = []
sum = 0
result = "Yes"
for _ in range(N):
    cost, limit = map(int, input().split())
    job.append((limit,cost))

job.sort()
for i,j in job:
    sum += j
    if i < sum:
        result = "No"
        break

print(result)

Submission status: Accepted

Solution code:
import numpy as np
N =int(input())

A = np.zeros((N,2))


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



B = A[A[:,1].argsort(),:]    


sa = B[0,0]
i = 0
while i < N-1 and sa <= B[i,1]:
    i +=1
    sa += B[i,0]


    
if i == N -1 and sa <=B[i,1]:
  
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
L = []
for i in range(N):
    L.append(list(map(int,input().split())))
L.sort(key=itemgetter(1))
flag = 0
sum = 0
for i in range(N):
    sum = sum + L[i][0]
    if sum > L[i][1]:
        flag = 1
        break
if flag == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
def solve():
    flag = True
    N = int(input())
    schedules = []
    for _ in range(N):
        a,b = input().split(' ')
        schedules.append((int(a),(int(b))))
        
    s_s = sorted(schedules, key=lambda x:x[1])
    time = 0
    for s,limit in s_s:
        time += s;
        if(time > limit): 
            flag = False
            break
    if flag:
        print('Yes')
    else:
        print('No')

solve()