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

sum = 0
ab.sort(key=lambda x: x[1])
for i in range(n):
    sum += ab[i][0]
    if sum > ab[i][1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            print("Bad")
            quit()
    print("Good")
    return

#B
def B():
    n,l = LI()
    a = [i+l for i in range(n)]
    ans = sum(a)
    m = n+l-1
    for i in a[::-1]:
        if i < 0:break
        m = min(m,i)
    ans -= m
    print(ans)
    return

#C
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
def C():
    a,b,c,d = LI()
    g = gcd(c,d)
    l = c*d//g
    sc = b//c-(a-1)//c
    sd = b//d-(a-1)//d
    sl = b//l-(a-1)//l
    print(b-a+1-sc-sd+sl)
    return

#D
def D():
    n = I()
    w = LIR(n)
    w.sort(key = lambda x: x[1])
    t = 0
    for a,b in w:
        if t+a > b:
            print("No")
            quit()
        t += a
    print("Yes")
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
X=sorted([tuple(map(int,input().split())) for i in range(N)],key=lambda x:x[1])
S=0
for i in range(N):
    S+=X[i][0]
    if S<=X[i][1]:
        pass
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import fractions

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    task = [tuple(map(int, input().split())) for _ in range(n)]
    tmp = 0
    task.sort(key=lambda x:x[1])
    for a, b in task:
        tmp += a
        if tmp > b:
            print("No")
            return
    print("Yes")

main()

Submission status: Accepted

Solution code:
n = int(input())

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

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

curr_time = 0

for task, time_limit in tasks:
    curr_time += task
    if curr_time > time_limit:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

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

for a, b in A:
    S += a
    if S > b:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

#n,l = [int(i) for i in input().split()]

n = int(input())
ab = [[int(i) for i in input().split()] for j in range(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())

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

C.sort(lambda x:x[1])

S = 0
flag=True
for i in range(N):
    S+=C[i][0]
    if S>C[i][1]:
        flag=False
        break

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

Submission status: Accepted

Solution code:

N = int(input())

A = [[int(i) for i in input().split()]for _ in range(N)]
A = sorted(A, key=lambda x:x[1])
total = 0
ret = "Yes"
for i in A:
	total += i[0]
	if total > i[1]:
		ret="No"
		break
print(ret)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
BAs = []
for i in range(N):
    A,B = inpl()
    BAs.append([B,A])

BAs.sort()

now = 0
for B,A in BAs:
    now += A
    if now <= B:
        continue
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

n = int(input())
a = [[int(i) for i in input().split()] for i in range(n)]
a.sort(key = lambda x:x[1])
timer = 0
goodbad = 0
for i in range(n):
    timer += a[i][0]
    if timer > a[i][1]:
        goodbad = 1
if goodbad == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1))
t = 0
for a, b in AB:
    t += a
    if t > b:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    T = []
    for i in range(N):
        a, b = map(int, input().split())
        T.append((a, b))
    T.sort(key=lambda x: x[1])
    p = 0
    fail = False
    for i in range(N):
        p += T[i][0]
        if p > T[i][1]:
            fail = True
    print('No' if fail else 'Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

import os
import sys
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

import random
import collections
import math
import itertools
import bisect

def real_main():
    N = read_int()
    jobs = [read_int_array() for _ in range(N)]
    order = mergesort(jobs, key=lambda p: p[1])
    t = 0
    for i in order:
        c, d = jobs[i]
        t += c
        if d < t:
            print("No")
            return
    print("Yes")



def solve():
    pass


def main():
    if False and 'PYCHARM_HOSTED' in os.environ:
        main_pycharm()
    else:
        real_main()


from copy import deepcopy
def main_pycharm():
    solution = solve

    test_inputs = None
    test_outputs = None
    judge = None
    slow_solution = None
    if solution is not None:
        if test_outputs is not None:
            test_with_answers(solution, test_inputs, test_outputs)
        if judge is not None:
            test_with_judge(solution, test_inputs, judge)
        if slow_solution is not None:
            test_with_slow_solution(solution, test_inputs, slow_solution)


def test_with_answers(solution, inputs, answers):
    total, wrong = 0, 0
    for args, test_ans in zip(inputs, answers):
        ans = solution(*deepcopy(args))
        if ans != test_ans:
            print('WRONG! ans=%s, test_ans=%s, args=%s' % (ans, test_ans, args))
            wrong += 1
        else:
            print('GOOD')
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


def test_with_judge(solution, inputs_gen, judge):
    total, wrong = 0, 0
    for args in inputs_gen:
        ans = solution(*deepcopy(args))
        if not judge(deepcopy(ans), *deepcopy(args)):
            print('WRONG! ans=%s, args=%s' % (ans, args))
            wrong += 1
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


def test_with_slow_solution(solution, inputs_gen, solution_slow):
    total, wrong = 0, 0
    for args in inputs_gen:
        ans = solution(*deepcopy(args))
        slow = solution_slow(*deepcopy(args))
        if ans != slow:
            print('WRONG! ans=%s, slow=%s, args=%s' % (ans, slow, args))
            wrong += 1
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


# This mergesort can be like 7 times faster than build in sort
# (for stupid reasons)
def mergesort(A, key=lambda x: x, reverse=False):
    C = A
    A = list(range(len(A)))
    B = list(A)

    n = len(A)
    for i in range(0, n - 1, 2):
        if key(C[A[i]]) > key(C[A[i ^ 1]]):
            A[i], A[i ^ 1] = A[i ^ 1], A[i]

    width = 2
    while width < n:
        for i in range(0, n, 2 * width):
            R1, R2 = min(i + width, n), min(i + 2 * width, n)
            j, k = R1, i
            while i < R1 and j < R2:
                if key(C[A[i]]) > key(C[A[j]]):
                    B[k] = A[j]
                    j += 1
                else:
                    B[k] = A[i]
                    i += 1
                k += 1
            while i < R1:
                B[k] = A[i]
                k += 1
                i += 1
            while k < R2:
                B[k] = A[k]
                k += 1
        A, B = B, A
        width *= 2

    if reverse:
        A.reverse()
    return A


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

def read():
    return input()

def read_int():
    return int(input())

def read_array(sep=None, maxsplit=-1):
    return input().split(sep, maxsplit)

def read_int_array():
    return [int(a) for a in read_array()]

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

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

def solve(N: int, A: "List[int]", B: "List[int]"):
    p = []
    for i in range(N):
        p.append([A[i], B[i]])
    p.sort(key=lambda x: x[1])
    tmp = 0
    ret = YES
    for i in range(N):
        tmp += p[i][0]
        if tmp > p[i][1]:
            ret = NO
            break
    print(ret)
    return


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 sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
ws = []
for i in range(n):
    ws.append(na())

ws.sort(key=lambda x: x[1])
t = 0
for w in ws:
    t += w[0]
    if t > w[1]:
        print("No")
        sys.exit(0)
print("Yes")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    jobs = [None] * N
    for i in range(N):
        A, B = map(int, input().split())
        jobs[i] = (B, A)
    jobs.sort()
    t = 0
    for B, A in jobs:
        t += A
        if t > B:
            print("No")
            return
    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
arr=[]
for i in range(n):
	a,b=map(int,input().split())
	arr.append((b,a))
arr.sort()
time=0
flag=0
for i in range(n):
	if(time+arr[i][1]>arr[i][0]):
		flag=1
		break
	else:
		time+=arr[i][1]

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

a.sort(key=itemgetter(1))

p = 0

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

print('Yes')

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    AB = LLIN(N)
    AB.sort(key=lambda x: x[1])
    now = 0
    for a, b in AB:
        if b - now >= a:
            now += a
        else:
            print("No")
            exit()
    print("Yes")
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

X = sorted(X, key = lambda x:x[1])
t = 0
for i in range(N):
    t += X[i][0]
    if t > X[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    AB = []
    for _ in range(N):
        a, b = LI()
        AB.append([b, a])
    AB.sort()
    ans = True
    time = 0
    for b, a in AB:
        time += a
        if time > b:
            ans = False
            break
    ans = YesNo(ans)
    return ans

print(main())

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

NOW=0
for x,y in AB:
    NOW+=x
    if NOW>y:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
# 締切が早いものから処理
N = int(input())
AB = np.array([[int(x) for x in input().split()] for _ in range(N)])
A = AB[:,0]
B = AB[:,1]
idx = B.argsort()
A = A[idx]
B = B[idx]
np.cumsum(A, out = A)
bl = (A <= B).all()
answer = 'Yes' if bl else 'No'
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = list(map(int, input().split()))
a.sort(key = lambda x: x[1], reverse = True)

#print(a)
now = a[0][1]
for time, lmt in a:
    now = min(now, lmt)
    now -= time
if now < 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    ab = ip.SILS(n)
    id.S(ab, 1, 1)
    ab = np.array(ab)
    memo = ab.sum(axis=0)[0]
    res = memo
    f = False
    for i, x in e(ab):
        if res <= x[1]:
            res -= x[0]
        else:
            f = True
            break
    if f:
        print("No")
    else:
        print("Yes")


main()

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=[]
b=[]
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
x=np.argsort(b)
g=0
f=0
for i in range(n):
    g+=a[x[i]]
    if b[x[i]]<g:
        f+=1
if f>0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
L.sort(key=lambda x:x[1])
cr=0
chk=1
ll=0
for i in range(N):
  a,b=L[i]
  cr+=b-ll-a
  if cr<0:
    chk=0
    break
  ll=b
  
print("Yes" if chk else "No")

Submission status: Accepted

Solution code:
n=int(input())
w=[[int(_) for _ in input().split()] for __ in range(n)]
w.sort(key=lambda x: x[1])
t=0
for i in range(n):
    t += w[i][0]
    if t > w[i][1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key = itemgetter(1))
now = 0
ans = "Yes"
for i in ab:
    a,b = i[0],i[1]
    now += a
    if now > b:
        ans = "No"
        break
print(ans)

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

Submission status: Runtime Error

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

    ba_lst = [0] * n
    for i in range(n):
        a = ab_lst[i][0]
        b = ab_lst[i][1]
        ba = [b, a]
        ba_lst[i] = ba
    ba_lst.sort()

    lst = []
    b = ba_lst[0][0]
    a = ba_lst[0][1]
    for i in range(n):
        b_tmp = ba_lst[i][0]
        a_tmp = ba_lst[i][1]

        if b == b_tmp:
            if i != 0:
                a += a_tmp
            if i == n - 1:
                lst.append([b, a])

        else:
            lst.append([b, a])
            b = b_tmp
            a = a_tmp

    if ba_lst[-1][0] != ba_lst[-2][0]:
        lst.append([ba_lst[-1][0], ba_lst[-1][1]])

    print(lst)

    accumulate = 0
    flag = True
    for i in range(len(lst)):
        accumulate += lst[i][1]
        if accumulate > lst[i][0]:
            flag = False
            break

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
work = [list(map(int,input().split())) for _ in range(n)]
work = sorted(work,key = lambda x:x[1])
a = [0] * n
a[0] = work[0][0]
for i in range(1,N):
    a[i] = a[i-1] + work[i][0]
ans = 'Yes'
for j in range(N):
    if a[j] > work[j][1]:
        ans = 'No'
        break
print(ans)

Submission status: Runtime Error

Solution code:
#35 C - Anti-Division　
import math
A,B,C,D = map(int,input().split())

# C と D の最小公倍数の個数
lcm = C*D//math.gcd(C,D)
cnt_lcm = B//lcm - A//lcm

# C の倍数の個数
cnt_C = B//C - (A-1)//C 

# D の倍数の個数
cnt_D = B//D - (A-1)//D

# (範囲内の整数) - (C の倍数 + D の倍数 - C,D の公倍数)
ans = (B - A + 1) - (cnt_C + cnt_D - cnt_lcm)

# 範囲が 1 しかないとき
if A == B:
    # C でも D でも割り切れるとき
    if A%C == 0 and A%D == 0:
        print(0)
    else:
        print(1)
else:
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

job.sort(key = lambda x: x[1])
#print(job)
for i in range(1, N):
    job[i][0] += job[i - 1][0]
for i in range(N):
    if job[i][0] > job[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
5
2 4
1 9
1 8
4 9
3 12

Submission status: Runtime Error

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

sort_AB = sorted(AB, key= lambda x: x[1])
ans = 'Yes'
tmp = 0

for i in range(N):
    tmp += sortedAB[i][0]
    if tmp > sortedAB[i][1]:
        ans = 'No'
        break
        
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

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

A.sort(lambda x: x[1], x[0])

gokei = 0
for i in A:
    gokei += i[0]
    if gokei > i[1]:
        print("No")
else:
    print("Yes")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

n = int(input())

readline = sys.stdin.readline

MAX_N = 10**9+5
w = [0]*MAX_N

for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    w[b] += a

s = 0
for i in range(MAX_N):
    if w[i]:
        s += w[i]
        if s > i:
            print('No')
            break
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
#b = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#
readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

MAX_N = 10**5*2+5
w = [0]*MAX_N

for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    w[b] += a

s = 0
for i in range(MAX_N):
    if w[i]:
        s += w[i]
        if s > i:
            print('No')
            break
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
from typing import List


class Work:
    require = 0
    limit = 0
    def __init__(self, require, limit) -> None:
        self.require = require
        self.limit = limit

def from_list(xs: List[int]) -> Work: 
    return Work(xs[0], xs[1])

N = int(input())

works = [from_list([int(_) for _ in input().split()]) for i in range(N)]

def solve(works):
    works.sort(key=lambda x: x.limit)
    acc = 0
    for w in works:
        acc += w.require
        if acc > w.limit:
            return "No"
    return "Yes"

print(solve(works))

Submission status: Runtime Error

Solution code:
ef main():
    N = int(input())
    jobs = [list(map(int, input().split())) for _ in range(N)]
    time = 0
    jobs = sorted(jobs, key=lambda x: x[1])
    for j in jobs:
        time += j[0]
        if time > j[1]:
            print("No")
            return
        
    else:
        print("Yes")


if __name__ == '__main__':
    main()