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())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[1])

ok = True
time = 0
for a, b in AB:
  time += a
  if time <= b: continue
  else:
    ok = False
    break
print("Yes" if ok else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    tasks=[tuple(map(int, input().split())) for _ in range(N)]

    from operator import itemgetter
    tasks.sort(key=itemgetter(1))
    t=0
    for task in tasks:
        t += task[0]
        if t > task[1]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

AB.sort()
t = 0
for i in range(n):
    t += AB[i][1]
    if t > AB[i][0]:
        print('No')
        exit()
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
ab = [LIST() for _ in range(n)]
ab.sort(key=lambda x:x[1])
tim = 0
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    if tim + a > b:
        print('No')
        exit()
    tim += a
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    task = []
    for _ in range(n):
        task.append(list(map(int, input().split())))
    time = 0
    task.sort(key=lambda x: x[1])
    answer = True
    for i in range(n):
        required_time, deadline = task[i]
        if deadline < time + required_time:
            answer = False
        else:
            time += required_time
    print("Yes" if answer else "No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    from operator import itemgetter
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if b < t:
            return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
x = [list(map(int, input().split())) for i in range(N)]  # x11 x12
x.sort(key=lambda x: x[1])
limit = 0
for i in range(N):
    limit += x[i][0]
    if limit > x[i][1]:
        print('No')
        exit()
    else:
        pass
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
A=[]
B=[]
# for i in range(N):
#     a, b = map(int, input().split())
#     A.append(a)
#     B.append(b)
x = [list(map(int, input().split())) for i in range(N)]  # x11 x12
x.sort(key=lambda x: x[1])
limit = 0
for i in range(N):
    limit += x[i][0]
    if limit > x[i][1]:
        print('No')
        exit()
    else:
        pass
else:
    print('Yes')

Submission status: Accepted

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

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

print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
ls = sorted(sorted([list(map(int,input().split())) for _ in range(N)]),key=itemgetter(1))



flag = 1
t = 0
for i in range(N):
  t += ls[i][0]
  if ls[i][1] < t:
    flag = 0
    print("No")
    break

if flag == 1:
  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])
time = 0

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

print("Yes")

Submission status: Accepted

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

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

tasks.sort()

ans = "Yes"
time = 0
for task in tasks:
    time += task[1]
    if time > task[0]:
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

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

tasks.sort()

ans = "Yes"
time = 0
for task in tasks:
    time += task[1]
    if time > task[0]:
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def i() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N = I()
AB = LRI(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")

Submission status: Accepted

Solution code:
n = int(input())
ab = []
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    ab.append(tmp)

AB = sorted(ab, key=lambda x: x[1])
ans = "Yes"
time = 0

for x in AB:
    time += x[0]
    if time > x[1]:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    ab[i][0]  = b
    ab[i][1] = a
ab.sort()
ok = True
time = 0
for i in range(n):
    cost = ab[i][1]
    due = ab[i][0]
    if time+cost > due:
        ok = False 
        break
    time += cost
if ok:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
def q4():
    N = int(input())
    D = []
    for i in range(N):
        l = [int(i) for i in input().split()]
        D.append({'A': l[0], 'B': l[1]})
    D.sort(key=lambda x: x['A'])
    D.sort(key=lambda x: x['B'])

    time = 0
    ans = 'Yes'
    for d in D:
        time += d['A']
        if time > d['B']:
            ans = 'No'
            break
    print(ans)


if __name__ == '__main__':
    q4()

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=sorted(AB, key=lambda x: x[1])

addtime=0
nowtime=0
for i in range(N):
  a=AB[i][0]
  b=AB[i][1]
  nowtime+=a
  if nowtime>b:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2**61+1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

def iip(listed=True):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def iip_ord():
    return [ord(i) - ord("a") for i in input()]


def main():
    ans = solve()
    if ans is not None:
        print(ans)

def solve():
    N = iip(False)
    A = [iip(False) for i in range(N)]

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

    t = 0
    #print(A)
    for i in A:
        a, b = i
        #print(a, b, b-a, t)
        t += a
        if t > b:
            return "No"
    return "Yes"



#####################################################ライブラリ集ここから

def YesNo(s):
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):
    for i in s:
        print(i)

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_= mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Accepted

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

n = int(input())
task = []
time_total = [-1 for i in range(n)]
for i in range(n):
    task.append([int(i) for i in input().split()])
task_sorted = sorted(task, key = lambda x:x[1])
time_total[0] = task_sorted[0][0]
for i in range(n - 1):
    time_total[i + 1] = time_total[i] + task_sorted[i + 1][0]
for i in range(n):
    if time_total[i] > task_sorted[i][1]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
li = []
for n in range(N):
    li.append([int(i) for i in list(input().split())])
arr = np.array(li)
ruiseki = 0
for a in arr[np.argsort(arr[:,1], axis=0)]:
    if ruiseki + a[0] > a[1]:
            yn = "No"
            break
    else:
        yn = "Yes"
        ruiseki+=a[0]
print(yn)

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))
time = 0
ans = "Yes"
for i in AB:
    time = time + i[0]
    if time>i[1]:
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

time=0
for a,b in l:
  time+=a
  if time>b:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
"""
締め切りの早いものから実施。
作業時間が締め切りをオーバーしたらFalse
"""

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB = sorted(AB, key=lambda x: x[1])
A, B = list(zip(*AB))
B = np.array(B)
cumsum_A = np.array(A).cumsum()
# print('cumsum_A', cumsum_A)

ans = 'Yes' if np.count_nonzero(B >= cumsum_A) == N else 'No'
print(ans)

Submission status: Accepted

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

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

ans,time,count = True,0,0
while count < N and ans:
	time += AB[count][0]
	if time > AB[count][1]:
		ans = False
	count += 1

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])

time = 0
for a, limit in ab:
    time += a
    if limit < time:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

q = 0
w = 0
flg = 0
for j in a:
  q += j[0]
  w = j[1]
  if q > w :
    flg = 1
    break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

timer = 0
for a, b in ab:
    timer += a
    if timer > b:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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

result = 'Yes'

for job in jobs:
    time += job[0]
    if time > job[1]:
        result = 'No'
        break

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

from operator import itemgetter
ab.sort(key=itemgetter(1))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
works=sorted([list(map(int,input().split()))[::-1] for i in range(n)])
time=0
ans='Yes'
for i in range(n):
  time+=works[i][1]
  if time>works[i][0]:
    ans='No'
print(ans)

Submission status: Accepted

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

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

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

ans = 0
for k,v in t:
    ans += k
    if ans > v:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:

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

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

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

t = 0
ok = True
for a,b in task:
    if t+a>b:
        ok = False
        break

    t += a

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

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

ct = 0

for item in ab_list:
    ct += item[0]
    if ct > item[1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
works = [tuple(map(int, input().split())) for _ in range(N)]
works.sort(key=itemgetter(1))

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

Submission status: Accepted

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

time = 0
res = True
for i in range(n):
    time = time + tasks[i][1]
    if time > tasks[i][0]:
        res = False
print("Yes" if res else "No")

Submission status: Accepted

Solution code:
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X = sorted(X, key = lambda x: x[1])
'''
Bi についてソートするときには当然ながら 
Aiもこれにしたがってソートしたいので、便宜上これらを 
Xi とまとめてしまいます。
'''
# a[i]はA[i]まで終わらせるためにかかる累積時間
a = [0] * N
a[0] = X[0][0]
for i in range(1, N):
	a[i] = a[i - 1] + X[i][0]

for j in range(N):
	if a[j] > X[j][1]:
		print("No")
		exit()
print("Yes")

Submission status: Accepted

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n = int(input())
  works = []
  for i in range(n):
    t, limit = input_list()
    works.append((t, limit))
  sw = sorted(works, key=lambda x: x[1])
  total = 0
  for t, limit in sw:
    total += t
    if total > limit:
      print('No')
      exit(0)
  print('Yes')
  
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ab = sorted(ab, key=lambda x: x[1])
a_sum = 0
ans = 'Yes'
for i in range(n):
    a_sum += ab[i][0]
    if a_sum>ab[i][1]:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x:x[1])
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            return False
    return True

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

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])
work = 0
for a in A:
    work += a[0]
    if work>a[1]:
        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())))
#print(N, AB)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def main():
    n = int(input())
    abs = []
    for i in range(n):
        a, b = map(int, input().split())
        abs.append((a, b))
    abs = sorted(abs, key=(lambda x: x[1]))
    time = 0
    possible = True
    for i in range(n):
        time += abs[i][0]
        if time > abs[i][1]:
            possible = False
    print("Yes" if possible else "No")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

a = np.array(a_list)
b = np.array(b_list)
indices = b.argsort()
a = a[indices]
b = b[indices]
if np.all(np.cumsum(a) <= b):
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

Submission status: Accepted

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

task_sum = 0
for i in range(N):
    task_sum += AB[i][0]
    if(task_sum>AB[i][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 = sorted(ab, key=lambda x: x[1])
a = 0
for i, j in ab:
    a += i
    if a > j:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())

l=[]

for i in range(N):
  x,y=[int(x) for x in input().rstrip().split()]
  l.append([x,y])

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

flag=0
now=0
ans=0
for i,j in l:
  now+=i
  if j<now:
    print("No")
    flag=1
    break
if flag==0:
  print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

cnt = 0
for i in end_jobs:
    cnt += i[0]
    if cnt > i[1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

ab = sorted(ab)
total = 0

for i in range(n):
    b, a = ab[i]
    total += a
    if total>b:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
tasks = [[int(i) for i in input().split()] for i in range(n)]
sorted_tasks = sorted(tasks, key = lambda x: x[1])
passage = 0
in_time = True
for t in sorted_tasks:
    passage += t[0]
    if passage > t[1]:
        in_time = False
        break

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

Submission status: Accepted

Solution code:

n = int(input())

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

data.sort(key = lambda x: x[1])
flag = True
sum = 0
for i in range(n):
    sum += data[i][0]
    if sum > data[i][1]:
        flag = False
        break
print("Yes" if flag == True else "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]"):
    S = sorted([(B[i],A[i]) for i in range(N)])
    current = 0
    for i in range(N):
        current += S[i][1]
        if current > S[i][0]:
            print(NO)
            exit()
    print(YES)
    return


# Generated by 1.1.6 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:

N = int(input())
AB = [[0] * 2 for _ in range(N)]
time = [0] * N
out = 0
q = []
for i in range(N):
    tmp = list(map(int, input().split()))
    AB[i][0] = tmp[0]
    AB[i][1] = tmp[1]
    if AB[i][1] - AB[i][0] < 0:
        out = 1

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

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

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