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:
from operator import itemgetter
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
flag = True
AB.sort(key = itemgetter(1))
now = 0
for a, b in AB:
    now += a
    if now > b:
        flag = False

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

Submission status: Accepted

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: "List[int]", B: "List[int]"):

    L2 = [(b,b-a,a,b) for a,b in zip(A,B) ]
    L2.sort()

    t = 0
    for l in L2:
        if t > l[1]:
            print(NO)
            return
        t += l[2]

    print(YES)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import sys

n = int(input())

# jobs = pd.DataFrame(columns=["cost", "deadline"])

a = []
b = []

for i in range(n):
    aa, bb = map(int, input().split(' '))
    a.append(aa)
    b.append(bb)

a = np.array(a)
b = np.array(b)

sortIndex = np.argsort(b)

a = a[sortIndex]
b = b[sortIndex]

sum = 0
for i in range(n):
    sum += a[i]
    if sum > b[i]:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
inputlist = [0] * N
a = 0
b = 0
for i in range(N):
    inputlist[i] = [0]*2
    inputlist[i][1], inputlist[i][0] = map(int, input().split())
    # 締め切りを[i][0]にしている点に注意

inputlist = sorted(inputlist)

time = 0
ans = 0
for j in range(N):
    time += inputlist[j][1]
    if time > inputlist[j][0]:
        ans = 1

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

Submission status: Accepted

Solution code:
n = int(input())
sortsecond = lambda val : val[1]
a = []
time = 0
[a.append(list(map(int,input().split()))) for i in range(n)]
b = sorted(a, key=sortsecond)
for o,i in b:
    if time + o <= i:
        time+=o
    else :
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
import itertools
n = int(input())
ab = np.array([[int(i) for i in input().split()] for i in range(n)])
ab = ab[ab[:, 1].argsort(), :]

reqtime = list(itertools.accumulate(ab[:, 0]))
dead = ab[:, 1].tolist()
ans = 'Yes'
for d, r in zip(dead, reqtime):
    if d<r:
        ans  = 'No'
        break
print(ans)

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.sort()
    
ans = 0
t = 0
for i in range(N):
    if (t + l[i][1] <= l[i][0]):
        ans += 1
        t += l[i][1]

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

sum = 0
for k,i in enumerate(sorted_lsts):
  sum += i[0]
  if (sum > i[1]):
    print('No')
    break
  if (k == len(sorted_lsts) - 1):
    print('Yes')

Submission status: Accepted

Solution code:
from functools import cmp_to_key


def cmp(a, b):
    if a[1] == b[1]:
        return 0
    return -1 if a[1] < b[1] else 1

def main():
    N = int(input())
    T = []
    for _ in range(N):
        a, b = map(int, input().split())
        T.append([a, b])
    T2 = sorted(T, key=cmp_to_key(cmp))

    now = 0
    possible = 'Yes'
    for i in range(len(T2)):
        t = T2[i]
        deadline = t[1]
        now += t[0]
        if now > deadline:
            possible = 'No'
            break
    
    print(possible)
    

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

now = 0

f = 0
for i in range(n):
    now += ab[i][0]
    if now > ab[i][1]:
        f = 1
        break

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

Submission status: Accepted

Solution code:
N = int(input())
task = [tuple(map(int, input().split())) for _ in range(N)]
task.sort(key=lambda x:x[1])
done_task = 0
flag = 0
for i in range(N):
  done_task += task[i][0]
  if done_task <= task[i][1]:
    continue
  else:
    flag = 1
    break

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

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())
A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    A[i], B[i] = map(int, input().split())
idx = np.argsort(B)
A = A[idx]
B = B[idx]

A = np.cumsum(A)

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

print('Yes')

Submission status: Accepted

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

now = 0
for k in range(N):
    if now+G[k][0] > G[k][1]:
        print("No")
        exit(0)
    else:
        now += G[k][0]
print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
l= [list(map(int,input().split())) for i in range(n)]
l.sort(key = itemgetter(1))
#print(l)
ima = 0
gou = 0
for i, j in l:
    ima += i
    if ima > j:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

tasks = []
for _ in range(n):
	a, b = list(map(int, input().split()))
	c = b - 1
	tasks.append([a, b, c])

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

now = 0
for task in tasks:
	now += task[0]
	if now > task[1]:
		print("No")
		break 
else:
	print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

t=0
for ab in ABs:
    t+=ab[0]
    if t>ab[1]:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

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

count = 0
flag = 0
for a, b in AB_lis_sorted:
  count += a
  flag += 1
  if count > b:
    print("No")
    break
  if flag == N:
    print("Yes")
    break

Submission status: Accepted

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

sum_task=0
for i in range(n):
    sum_task+=info[i][0]
    if sum_task>info[i][1]:
        print("No")
        break
    else:
        if i==n-1:
            print("Yes")

Submission status: Accepted

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

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

    time = 0
    count = 0
    for i in range(N):
        flag = True
        a, b = AB[i]
        if time + a <= b:
            time += a
            count += 1
            flag = False
        if flag:
            break

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(N):
    tmp_a, tmp_b = input().split(' ')
    tmp_array = [int(tmp_b), int(tmp_a)]
    answer.append(tmp_array)

answer.sort()

now_time = 0

for item in answer:
    now_time += item[1]
    if now_time > item[0]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

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

#print()                                                                                 
t = 0
f = 0
for a,b in ab_list:
    #print(a,b,t)                                                                        
    t += a
    if t > b:
        f = 1
        break

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

Submission status: Accepted

Solution code:
N = int(input())
# works = 所要時間, 締め切り時間
works = [list(map(int, input().split())) for _ in range(N)]
# 終えられるか否かをチェックすればいい
# タスク締切の昇順＞タスクの所要時間の降順 でソートする
tmp = sorted(works, key=lambda x: x[0], reverse=True)
sorted_works = sorted(tmp, key=lambda x: x[1])

current_hour = 0
ans = "Yes"
for required_hour, dead_line in sorted_works:
    current_hour += required_hour
    if dead_line < current_hour:
        ans = "No"
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    import numpy as np
    N = int(input())
    A = np.array([list(map(int, input().split())) for __ in range(N)])
    l = A[np.argsort(A[:, 1])]

    t = 0
    for i in l:
        t += i[0]
        if t > i[1]:
            print('No')
            return
    print('Yes')

resolve()

Submission status: Accepted

Solution code:
n = int(input())
dat = [tuple(list(map(int,input().split()))) for i in range(n)]



from operator import itemgetter
  
dat2 = sorted(dat, key=itemgetter(1))
# print(dat2)




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

Submission status: Accepted

Solution code:
N = int(input())


li = []

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

flag = True
now = 0
li = sorted(li)

for a, b, c in li:
    now += b
    if now > c:
        print("No")
        flag = False
        break
        
if flag:
    print("Yes")

Submission status: Accepted

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

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

cnt=0
ans='Yes'
for k,v in a:
    cnt+=k
    if cnt>v:
        ans='No'
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

sumW = 0
for a in aaa:
    sumW += a[0]
    if sumW > a[1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

input = sys.stdin.readline
n = int(input())
tasks = sorted([list(map(int, input().split())) for _ in range(n)], key=itemgetter(1))

time = 0
cando = True
for task in tasks:
  time += task[0]
  if time > task[1]:
    cando = False
    
print('Yes' if cando else 'No')

Submission status: Accepted

Solution code:
n = int(input())

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

s = 0

for i in range(n):
    s += li[i][0]
    if li[i][1] < s:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

ct = 0
for i in j:
  ct += i[1]
  if ct > i[0]:
    print("No")
    break
else:
  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], x[0]))

t = 0
for a, b in AB:
    t += a
    if t > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
tasks = [tuple(map(int, input().split())) for _ in range(N)]
tasks.sort(key=itemgetter(1))
start = 0

for task in tasks:
    if start + task[0] > task[1]:
        print('No')
        sys.exit()
    start += task[0]

print('Yes')

Submission status: Accepted

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

for i in range(n):
  line = list(map(int, input().split()))
  items.append({'a':line[0], 'b':line[1]})
  
sorted_items = sorted(
  items,
  key = lambda x: (x['b'],x['a'])
)


sum = 0
answord = 'Yes'

for i in range(n):
  sum += sorted_items[i]['a']
  if sum > sorted_items[i]['b']:
    answord = 'No'
    break
    
print(answord)

Submission status: Accepted

Solution code:
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    inp = [int(x) for x in input().split()]
    A[i] = inp[0]
    B[i] = inp[1]

def sort(index):
    if len(index) <= 1:
        return index
    
    min_i = []
    max_i = []

    for i in index[1:]:
        if(B[i] < B[index[0]]):
            min_i.append(i)
        elif(B[i] > B[index[0]]):
            max_i.append(i)
        else :
            if (A[i] <= A[index[0]]):
                min_i.append(i)
            else:
                max_i.append(i)
    max_i.append(index[0])
    
    result = sort(min_i)
    result = result + sort(max_i)

    return result

si = sort(list(range(N)))
total = 0
for i in si:
    total += A[i]
    if(total > B[i]):
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

n = int(input())
ab_list = [list(map(int, input().split())) for _ in range(n)]
ab_list.sort(key=lambda i: i[1])
time = 0
for a, b in ab_list:
    time += a
    if time > b:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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

hoge.sort()
  
for i in range(n):
  #print(hoge[i][0],hoge[i][1])
  time+=hoge[i][1]
  if(time>hoge[i][0]):
    ans+=1
    
if(ans==0):
  print("Yes")
else:
  print("No")

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

Submission status: Accepted

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

from operator import itemgetter
              
se = sorted(e, key=itemgetter(1))
#print(se)
flg = 0
sm = 0
for i in range(N):
	sm += se[i][0]
	if sm > se[i][1]:
		print('No')
		break
#print(i)
if i == N-1 and sm <= se[N-1][1]:
	print('Yes')

Submission status: Accepted

Solution code:
import math
N = int(input())

listJob = []
sumAmount = 0
for i in range(N):
    amount, timelimit = map(int, input().split(' '))
    listJob.append((amount, timelimit))
    sumAmount += amount

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

def code(listJob, _sumAmount):
    sumAmount = _sumAmount
    currentTime = listJob[0][1]
    for i in listJob:
        currentTime = min(currentTime, i[1])
        sumAmount -= i[0]
        currentTime -= i[0]
        if currentTime < sumAmount:
            return "No"
    return "Yes"

print(code(listJob, sumAmount))

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())

BAList=[]
for i in range (N):
  A,B = map(int,stdin.readline().rstrip().split())
  BAList.append((B,A))

BAList.sort()
deadend=0
jobsum=0
for (B,A) in BAList:
  deadend=B
  jobsum+=A
  if jobsum>deadend:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
works = []
for i in range(N):
    temp= list(map(int,input().split(" ")))
    works.append(temp)
works.sort(key=lambda x:x[1])
sche ={}
for work in works:
    if work[1] not in sche:
        sche[work[1]] = work[0]
    else:
        sche[work[1]] += work[0]
acc = 0
sche = sorted(sche.items(), key=lambda x:x[0])

for k,v in sche:
    acc += v
    if acc > k:
        print("No")
        exit()

print("Yes")

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


time = 0
flag = True
for i in BA:

    time += i[1]

    if time > i[0]:
        flag = False

if flag:
    print("Yes")

else:
    print ("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
p = []
t = 0
ans = 'Yes'
for _ in range(n):
    a,b = map(int,input().split())
    p.append([a,b])
#print(p)
p = sorted(p, key=lambda x:x[1])
for a,b in p:
    t += a
    if t > b:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
listA=[list(map(int,input().split())) for i in range(N)]
listA.sort(key=lambda x:x[1])
jikan=0
deki=True
for i in range(N):
    jikan=jikan+listA[i][0]
    if jikan > listA[i][1]:
        deki=False
if deki:
    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 x: x[1])

time = 0
ans = "Yes"
for ab in AB:
  time += ab[0]
  if time > ab[1]:
    ans = "No"
    break
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N)]

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

flag = True
time = 0
for l in L:
    time += l[0]

    if time > l[1]:
        flag = False
        break

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

job = sorted(job, key=itemgetter(0), reverse=True)
job = sorted(job, key=itemgetter(1))

now = 0
des = True
for i, j in enumerate(job):
    j_time = j[0]
    j_dead = j[1]
    now += j_time
    if now > j_dead:
        des = False

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
AB=[]
TMP=[]
cnt=0
key=True
for i in range(n):
    a,b=map(int,input().split())
    TMP.append(a)
    TMP.append(b)
    AB.append(TMP)
    TMP=[]
AB=sorted(AB, key=lambda x: x[1])
for i in range(n):
    cnt+=AB[i][0]
    if AB[i][1]<cnt:
        key=False
        
if key==True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = []
    B = []
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        AB.append((a, b))
    if sum(A) > max(B):
        print('No')
        return
    AB = sorted(AB, key=lambda x: x[1])
    c = 0
    for a, b in AB:
        c += a
        if c > b:
            print('No')
            return
    print('Yes')


main()

Submission status: Accepted

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

x = []
y = []

for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)

x, y = np.array(x), np.array(y)

idx = np.argsort(y)
x = x[idx]
y = y[idx]

t = 0
for i in range(n):
    t += x[i]
    if y[i] < t:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
ab=[]
flg=0
for i in range(n):
    ab.append(list(map(int,input().split())))
t=0
ab.sort(key=lambda x:x[1])

for i in range(len(ab)):
    t+=ab[i][0]
    if t>ab[i][1]:
        flg=1
if flg==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A_B = [[int(i) for i in input().split()] for _ in range(N)]
A_B.sort(key=lambda x:x[1])

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

print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
d=[]
for _ in range(n):
  a,b=map(int,input().split())
  d.append([a,b])
l=sorted(d,key=lambda x: x[1])
z='Yes'
s=0
for i in range(n):
  s+=l[i][0]
  if s>l[i][1]:
    z='No'
    break
print(z)

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_spent = 0
for a,b in AB:
    time_spent += a
    if time_spent > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

job.sort(key=lambda x: x[1])
time=0
for j in job:
  time+=j[0]
  if time>j[1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

t = 0
t_limit = 0
task_s = sorted(task, key=lambda x: x[1])
ans = 1

for i in range(N):
    t += task_s[i][0]
    t_limit = task_s[i][1]

    if(t > t_limit):
        ans = 0
        break

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

Submission status: Accepted

Solution code:
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])
sum_a = 0
ans = 0

for i in range(N):
    sum_a += work[i][0]
    if sum_a > work[i][1]:
        ans = 1
        break


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

Submission status: Accepted

Solution code:
N=int(input())
works=[]
for i in range(N):
    [a,b]=[int(_) for _ in input().split()]
    works.append([b,a])
works.sort()
works2=works[:1]
for work in works[1:]:
    if work[0]==works2[-1][0]:
        works2[-1][1]+=work[1]
    else:
        works2.append([work[0],works2[-1][1]])
        works2[-1][1]+=work[1]

if all([work[0]>=work[1] for work in works2]):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())


li = []

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

flag = True
now = 0
li = sorted(li)

for a, b, c in li:
    now += b
    if now > c:
        print("No")
        flag = False
        break
        
if flag:
    print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
li=[]
for i in range(n):
    a,b=map(int,input().split())
    li.append([b,a])
    
li.sort()
y="Yes"
sum=0
for i in range(len(li)):
    sum+=li[i][1]
#    print(sum,li[i][0])
    if li[i][0]<sum:
        y="No"
        break
        
print(y)

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

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],reverse=True)

time = AB[0][1]
for i in range(1,N):
    if time-AB[i-1][0] < AB[i][1]:
        time = time-AB[i-1][0]
    else:
        time = AB[i][1]

time = time - AB[N-1][0]

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

Submission status: Accepted

Solution code:
n = int(input())
a, b = [], []
tmp_a, tmp_b = 0, 0
time_count = 0
result = 0

for i in range(n):
    tmp_a, tmp_b = map(int, input().split())
    a.append(tmp_a)
    b.append(tmp_b)

sort_data = zip(a, b)
sort_data = sorted(sort_data, key=lambda x:x[1])
a, b = zip(*sort_data)

for i in range(n):
    time_count += int(a[i])
    if time_count <= b[i]:
        result = 1
    else:
        result = 0
        break

if result == 1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

t = 0
flag = True
for i in range(n):
    t += l[i][0]
    if t > l[i][1]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from fractions import gcd


class Work():

    def __init__(self, a, b):
        self.a = a
        self.b = b

    def __lt__(self, other):
        return self.b < other.b

    def __eq__(self, other):
        return self.b == other.b

    def __repr__(self):
        return "Work(%d, %d)" % (self.a, self.b)


def read():
    N = int(input().strip())
    works = []
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        works.append(Work(a, b))
    return N, works


def solve(N, works):
    works = sorted(works)
    t = 0
    for work in works:
        t += work.a
        if t > work.b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

Solution code:
N = int(input())
AB = []
for _ in range(N):
    A, B = map(int, input().split())
    AB.append((A,B))
t = 0
flag = True
for (A, B) in sorted(AB, key = lambda x:x[1]):
    t += A
    if t > B:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = sorted(
        [list(map(int, input().rstrip().split())) for _ in range(n)], key=lambda x: x[1]
    )
    task_sum = 0
    for i, j in arr:
        task_sum += i
        if task_sum > j:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

n = int(input())
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append([b-a,b,a])
li.sort(reverse=True,key=itemgetter(1))
for i in range(n-1):
    if li[i][0] < li[i+1][1]:
        li[i+1][1] = li[i][0]
        li[i+1][0] = li[i+1][1] - li[i+1][2]
if li[-1][0] < 0:
    print("No")
else:
    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
t = 0
for i in range(n):
    t += ab[i][0]
    if t>ab[i][1]:
        flag = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
ab_sort = sorted(ab, key=lambda x: x[1])
#print(ab)
#print(ab_sort)

now = 0
for work in ab_sort:
    if now + work[0] <= work[1]:
        now += work[0]
    else:
        print('No')
        exit()
print('Yes')

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
possibility = 1

for l in AB:
  if l[0] + time > l[1]:
    possibility = 0
    break
  else:
    time += l[0]
    
if possibility == 1:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import heapq

N = int(input())

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

time = 0
can = True
for i in range(N):
    work = heapq.heappop(works)
    time += work[1]
    if time > work[0]:
        can = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())
AB=[]
for i in range(N):
  a,b = list(map(int, input().strip().split(' ')))
  AB+=[[b,a]]
AB.sort()
tim=0
for i in range(N):
  tim+=AB[i][1]
  if tim>AB[i][0]:print("No");exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
ab_list = [[int(i) for i in input().split()] for _ in range(n)]
ab_list.sort(key=lambda x:x[1])
t_sum = 0
flag = 0
a_before = 0
for a, b in ab_list:
  t_sum += a
  if b < t_sum:
    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 sc in ab:
    t += sc[0]
    if t > sc[1]:
        print("No")
        exit()
print("Yes")