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 main():
	import sys
	from operator import itemgetter
	input = sys.stdin.readline
	N = int(input())
	AB = [list(map(int, input().split())) for _ in range(N)]
	AB.sort(key=itemgetter(1,0))
	sum = 0
	for i in range(N):
		sum += AB[i][0]
		if sum > AB[i][1]:
			print('No')
			sys.exit()
	print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys
sys.dont_write_bytecode = True
stdin = sys.stdin
input = stdin.readline
sys.setrecursionlimit(10000000)

#import numpy as np
#import scipy as sp

# Python 3 modules: https://docs.python.org/3/library/

import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce, lru_cache
# Use scipy for stats: https://docs.scipy.org/doc/scipy/reference/stats.html
# Before Python 3.5.  Import from math after it.
from fractions import gcd
from fractions import Fraction as Frac

inf = float('inf')

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

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(func = input, sep = None, conv = int):
    return list(map(conv, func().split(sep = sep)))

################################################################################


def main():
    N, = list(map(int, input().split()))
    T = [None for i in range(N)]
    for i in range(N):
        T[i] = tuple(list(map(int, input().split())))
    T.sort(key = lambda t: t[1] * 1e10 + t[0])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())

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

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

flag = True
time = 0
for a, b in sorted_tasks:
    time += a
    if time > b:
        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) ]

cnt = 0
BA = [[0,0] for _ in range(N)]

for i in range(N):
    BA[i][1] = AB[i][0]
    BA[i][0] = AB[i][1]
BA.sort()
for i in range(N):
    cnt += BA[i][1]
    BA[i][1] = cnt
ans = "Yes"
for i in range(N):
    if BA[i][0] < BA[i][1]:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:

N=int(input())
a=[]

for i in range(N):
    yo=list(map(int,input().split()))
    a.append(yo)
#print(a)

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

#print(a)
t=0
k=0
for i in range(N):

    t+=a[i][0]
    if t<= a[i][1]:
        k=k
    else:
        k+=1
if k==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    AB = ii2nnn(N)
    AB.sort(key=lambda v: v[1])
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print('No')
            return
    print('Yes')

main()

Submission status: Accepted

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

time=0
for task in tasks:
    time+=task[0]
    if task[1]-time>=0:
        pass
    else:
        print('No')
        exit(0)
print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:


def read_input():
    n = int(input())

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

    return n, conds


def submit():
    n, conds = read_input()

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

    curr = 0
    for c in conds:
        curr += c[0]

        if curr > c[1]:
            print('No')
            return

    print('Yes')
    return


if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
def abc():
    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])
    tmp = 0
    for t in tasks:
        a, b = t
        if tmp + a > b:
            print('No')
            return
        tmp += a
    print('Yes')


abc()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict

n = II()
tasks = [0 for i in range(n)]
for i in range(n):
    tasks[i] = LI()
tasks = sorted(tasks, key=lambda x: x[1])
load = 0
for i in range(n):
    load += tasks[i][0]
    if load > tasks[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

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

c = 0
for i in range(N):
    x, y = L[i]
    
    c += x
    if c > y:
        print("No")
        exit()
      
print("Yes")

Submission status: Accepted

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

print("Yes")

Submission status: Accepted

Solution code:
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N = ni()
L = [na() for i in range(N)]

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

print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

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


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

def solve():
    time = 0
    for task in ab:
        if task[1] < task[0]+time:
            return False
        time = task[0]+time
    return True

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
c=sorted(ab, key=itemgetter(1), reverse=False)
f=True
t=0
for i in range(n):
    t = t + c[i][0]
    f=f and t<=c[i][1]
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
ab_list = [[int(x) for x in input().split()] for _ in range(N)]
sorted_ab_list = sorted(ab_list, key=lambda ab: ab[1])
t = 0
for a, b in sorted_ab_list:
    t += a
    if (t <= b):
        continue
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

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

time = 0
ans = True

for i in range(N) :
    time += AB[i][0]
    if time > AB[i][1] :
        ans = False
        break

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

Submission status: Accepted

Solution code:
from sys import stdin, exit

N = int(stdin.readline().rstrip())
work = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]

work.sort(key=lambda x: x[1])
time = 0
for k in range(N):
    if time + work[k][0] > work[k][1]:
        print('No')
        exit()
    time += work[k][0]
print('Yes')

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

input = sys.stdin.readline

N = int(input())

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

task_list.sort(key=itemgetter(1))

deadline = 0
time = 0

for task in task_list:
    time += task[0]
    deadline = task[1]
    if deadline < time:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
dic = defaultdict(list)

for i in range(1,N+1):
  inf = input().split()
  a = int(inf[0])
  b = int(inf[1])
  dic[b] += [a]

keys = list(dic.keys())
keys.sort()
ps = 0

for k in keys:
  ls = dic[k]
  need = sum(ls)
  ps += need
  if ps>k:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
import heapq
N = int(input())
q = []
heapq.heapify(q)
for i in range(N):
    a,b = map(int, input().split())
    heapq.heappush(q,(b,a))

time = 0
flg = True
for i in range(N):
    b,a = heapq.heappop(q)
    time += a
    # print(a,b,time)
    if b < time:
        flg = False
if flg:
    print("Yes")
else:
    print("No")

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)

idx = sorted(range(len(B)), key=lambda k: B[k])
time = 0
answer = 'Yes'
for i in idx:
    time += A[i]
    if (time > B[i]):
        answer = 'No'
        break

print(answer)

Submission status: Accepted

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

current_time = 0
answer = 'Yes'
for t in sorted(task, key=lambda x: x[1]):
    current_time += t[0]
    if current_time > t[1]:
        answer = 'No'
        break
print(answer)

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

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

Submission status: Accepted

Solution code:
N=int(input().strip())
a=[]
for i in range(N):
    array=list(map(int,input().strip().split()))
    a.append(array)
b=sorted(a, key=lambda x:x[1])
n,t,f=0,0,0
while True:
    t+=b[n][0]
    if t>b[n][1]:
        f=1
        break
    n+=1
    if n==N:
        break
if f==1:
    print('No')
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.sort(key=lambda x:(x[1],x[0]))

def check(ab_list):
    goukei = 0
    for a,b in ab_list:
        goukei += a
        if b < goukei:
#             print(a,b,goukei)
            return False
    return True

if check(ab_list):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
words = lambda t : list(map(t, input().split()))

n = int(input())
xs = []
for i in range(n):
    a,b = words(int)
    xs.append((b,a))

xs.sort()

ttl = 0
succeed = True
for b,a in xs:
    ttl += a
    if ttl > b:
        succeed = False
        break

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

Submission status: Accepted

Solution code:
def d_megalomania(N, Tasks):
    tasks = sorted(Tasks, key=lambda x: x[1])
    time = 0
    for a, b in tasks:
        time += a
        if time > b:
            return 'No'
    return 'Yes'

N = int(input())
Tasks = [[int(i) for i in input().split()] for j in range(N)]
print(d_megalomania(N, Tasks))

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
lst = [[0]*2 for i in range(n)]

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

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

a = np.array(lst).T.tolist()[0]
b = np.array(lst).T.tolist()[1]

time = 0
ans = 'Yes'
for i in range(n):
    time += a[i]
    if time > b[i]:
        ans = 'No'

print(ans)

Submission status: Accepted

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

end = 0
ans = 0
AB = sorted(AB,key=lambda x:x[1])
t = 0
for y in AB:
    t += y[0]
    if t > y[1]:
        print("No")
        exit()



print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
A = [0] * N
B = [0] * N
l = []

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

l.sort()
sum = 0
flag = 0

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

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()
#print(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:
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n=int(input())
l=[list(intinput()) for i in range(n)]
l.sort(key=lambda x:x[1])
k=0
for i,j in l:
    k+=i
    if k>j:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())
# n行複数列の数をリストに
ab = [[int(i) for i in input().split()] for i in range(n)] 


#print(ab)

# ソート　キーは0
ab = sorted(ab, key=lambda x:x[1])
t=0
for i in range(n):
    t += ab[i][0]
    if ab[i][1]<t:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import heapq


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

    heapq.heapify(q)

    t = 0
    while q:
        b, a = heapq.heappop(q)
        t += a
        # print(a, b)
        if t > b:
            print("No")
            return
    print("Yes")



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [0] * n
b = [0] * n
infob= [[0,0] for _ in range(n)]

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

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

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

print(ans)

Submission status: Accepted

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

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

total_amount = sum([w[0] for w in works])
#print(total_amount)

can_fin = True
for amount, deadline in reversed(works):
    if total_amount > deadline:
        can_fin = False
        break
    total_amount -= amount
    
if can_fin:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter
import math
N = int(input())
work_list = [[int(i) for i in input().split()] for i in range(N)]
new_worklist=sorted(work_list, key=itemgetter(1))
now_time = 0
for i in range (N):
	now_time += new_worklist[i][0]
	if now_time > new_worklist[i][1]:
		print("No")
		break
	if i == N-1:
		print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
jobs = defaultdict(int)
for i in range(N):
    Ai, Bi = map(int, input().split())
    jobs[Bi] += Ai

acu = 0
able = True
for Bi in sorted(jobs.keys()):
    acu += jobs[Bi]
    if acu > Bi:
        able = False
        break

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

Submission status: Accepted

Solution code:

def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

n = int(input())
jobs = []

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

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

flag = False
now_limit = 0
past = 0
for i in range(n):
    now_limit = jobs[i][1]
    past += jobs[i][0]
    if past > now_limit:
        flag = True
        break

if flag:
    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])
tmp = 0
flag = True
for part in AB:
  a, b = part
  tmp+=a
  if tmp>b:
    flag = False
    break
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
N = int(input())
Task = []
now = 0
is_clear = 0
for i in range(N):
  a, b = map(int, input().split())
  Task.append((b, a))

Task.sort()

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

Submission status: Accepted

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

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

cur = 0
flag = True
for a, b in L:
    cur += a
    if cur > b:
        flag = False
        break

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

Submission status: Accepted

Solution code:
import sys

fin = sys.stdin.readline
n = int(fin())
ab = [tuple(map(int, fin().split())) for i in range(n)]

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

cum = []
for i in range(n):
    if cum:
        cum.append(cum[-1] + ab[i][0])
    else:
        cum = [ab[i][0]]

for i in range(n):
    if cum[i] > ab[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  AB = [[int(i) for i in input().split()] for i in range(N)]
  AB.sort(key=lambda e: e[1])
  time = 0
  for ab in AB:
    a, b = ab
    time += a
    if time > b: return 'No'

  return 'Yes'

print(solve())

Submission status: Accepted

Solution code:
def foo():
    N = input()
    data = [map(int, raw_input().split()) for _ in range(N)]
    data.sort(key=lambda x: (x[1], x[0]))

    total = 0
    for a, b in data:
        total += a
        if total > b:
            return "No"
    return "Yes"

print foo()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from collections import defaultdict
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    d = defaultdict(int)
    for _ in range(n):
        a, b = map(int, input().split())
        d[b] += a

    s = sorted(d.items(), key=lambda x: x[0])
    pf = 0

    for b, a in s:
        pf += a
        if pf > b:
            print("No")
            return

    print("Yes")


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())

ab = [0]*N

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


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


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

print(ans)

Submission status: Accepted

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

    C = sorted(zip(A, B), key=lambda x: x[1])

    cumsum = 0
    for n in range(N):
        cumsum += C[n][0]
        if cumsum > C[n][1]:
            print('No')
            return
    print('Yes')


main()

Submission status: Accepted

Solution code:
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    ab_list = [tuple(map(int, input().split())) for _ in range(n)]
    ab_list.sort(key=lambda x: x[1])
    time_elapsed = 0
    is_ok = True
    for ab in ab_list:
        time_elapsed = time_elapsed + ab[0]
        if time_elapsed > ab[1]:
            is_ok = False
            break
    if is_ok:
        print("Yes")
    else:
        print("No")

# 締め切りが早い順に並び替える
# 締め切りが早い順に取り掛かって、間に合わない仕事が１つでもあればNoなければYes

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

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

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

Submission status: Accepted

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

a = sorted(a, key=lambda x:x[1])
time = 0
for w, lim in a:
    time += w
    if(time > lim):
        flag = False
        break

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    L = []

    for i in range(n):
        a, b = map(int, input().split())  # 複数数値入力
        L.append([b, a])

    L.sort()
    sum = 0
    for l in L:
        sum += l[1]
        if sum > l[0]:
            print("No")
            return

    print("Yes")

main()

Submission status: Accepted

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

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

atime = 0
for time, dead in sorted_works:
  atime += time
  if atime > dead:
    print("No")
    break
else:
  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])

ab

total_time = 0
for i in range(n):
    total_time += ab[i][0]

flag = True
time = total_time
for i in range(n):
    _ab = ab.pop(-1)

    if time > _ab[1]:
        flag = False
    time -= _ab[0]

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 x: x[1], reverse=True)
limit = ab[0][1] - ab[0][0]
for a, b in ab[1:]:
    limit = min(limit, b) - a
    if limit < 0:
        print("No")
        break
else:
    if limit < 0:
        print("No")
    else:
        print("Yes")

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

can = True
cum = 0
for ba in BA:
    cum += ba[1]
    if cum > ba[0]:
        can = False
        break

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

Submission status: Accepted

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

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lt = []
    for _ in range(n):
        a, b = rli()
        lt.append((b, a))
    t = 0
    lt.sort()
    for b, a in lt:
        t += a
        if t > b:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import heapq

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

t = 0
for i in range(n):
  b, a = heapq.heappop(q)
  t += a
  if t > b:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
import queue


def megalomania(N: int, tasks: list)->bool:
    que = queue.PriorityQueue()

    for a, b in tasks:
        que.put((b, a))

    time = 0
    while not que.empty():
        b, a = que.get()
        time += a
        if time > b:
            return False

    return True


if __name__ == "__main__":
    N = int(input())
    tasks = [tuple(int(s) for s in input().split()) for _ in range(N)]

    yes = megalomania(N, tasks)
    print('Yes' if yes else 'No')

Submission status: Accepted

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

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

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

ans = 'No'
time = 0
for i, (Ai, Bi) in enumerate(AB):
    time += Ai
    if time > Bi: break
else:
    ans = 'Yes'

print(ans)