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 = sorted(AB, key=lambda x: x[1])
A_sum=0
hantei = True
for i in range(N):
  A_sum += AB[i][0]
  if A_sum>AB[i][1]:
    hantei=False
    break
print('Yes' if hantei else 'No')

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:
N = int(input())

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

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

sum_value = 0
result = "Yes"
for val in sortV:
    sum_value += val[0]
    if sum_value > val[1]:
        result = "No"
        break

print(result)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        l.append((a,b))
    l.sort(key=lambda x:x[1])
    s = 0
    for i, j in l:
        s += i
        if s > j:
            return('No')
    return('Yes')
print(main())

Submission status: Accepted

Solution code:
# 2019-11-14 20:54:46(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n = int(sys.stdin.readline().rstrip())
    ab = [tuple(int(x) for x in sys.stdin.readline().split()) for _ in range(n)]
    ab.sort(key=lambda x: x[1])

    s = 0
    for i in range(n):
        s += ab[i][0]
        if s <= ab[i][1]:
            continue
        else:
            ans = 'No'
            break
    else:
        ans = 'Yes'
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array([[int(i) for i in input().split(" ")] for j in range(n)])
arg = np.argsort(a[:,1])
sa = a[:,0][arg]
sb = a[:,1][arg]
tm = 0
flag = 0
for i in range(len(sa)):
    tm += sa[i]
    if tm > sb[i]:
        flag = 1
        break
if flag == 1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

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

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

tasks = sorted( tasks, key = lambda a: a[1] )

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

Submission status: Accepted

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

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

tasks.sort()
tasks = sorted( tasks, key = lambda a: a[1] )

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

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

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

Submission status: Accepted

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

time = 0
flg = True
for i in l:
    time += i[0]
    if time > i[1]:
        flg = False
        break
    
print('Yes' if flg else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[1]-x[0])
cur = 0
aki = 0
if sum([a for a, b in AB]) <= max([b for a, b in AB]):
    for a, b in AB:
        if cur <= b-a:
            aki += (b-a)-cur
            cur += (b-a)-cur+a
        else:
            if aki >= a:
                aki -= a
            else:
                a -= aki
                if cur + a > b:
                    print('No')
                    exit()
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import heapq
n = int(input())
tasks = []
for _ in range(n):
  a,b = list(map(int, input().split()))
  heapq.heappush(tasks, (b, a))
res_a = 0
for i in range(n):
  b,a = heapq.heappop(tasks)
  res_a += a
  if(res_a > b):
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
# D - Megalomania
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

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

tmp = 0
for i in range(N):
    tmp += A[i][0]
    if tmp <= A[i][1]:
        pass
    else:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
def solve(n: int, ab: 'list(Task)') -> bool:
    from operator import attrgetter
    ab.sort(key=attrgetter('limit'))
    cur = 0
    for ab_ in ab:
        cur += ab_.cost
        if cur > ab_.limit:
            return False
    return True


if __name__ == '__main__':
    from collections import namedtuple
    import sys

    input = sys.stdin.readline
    Task = namedtuple('Task', 'cost limit')
    n = int(input())
    ab = []
    for _ in range(n):
        cost_, limit_ = map(int, input().split())
        ab.append(Task(cost=cost_, limit=limit_))
    print('Yes' if solve(n, ab) else 'No')

Submission status: Accepted

Solution code:
n = int(input().strip())
arr = [[0] * 2] * n

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

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

t = 0
flg = True

for e in s:
    if (e[1] < t + e[0]):
        flg = False
        break

    t += e[0]

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

Submission status: Accepted

Solution code:
N = int(input())
l = list()
for n in range(N):
    l.append([int(x) for x in input().split()])
l = sorted(l, key=lambda x:x[1])
sum = [l[0][0]]
for n in range(1,N):
    sum.append(l[n][0]+sum[n-1])
c = True
for n in range(N):
    if sum[n] > l[n][1]:
        c = False
if c:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

MOD = 10 ** 9 + 7


def main():
    N = int(input())
    A = [0] * N
    B = [0] * N
    h = []

    for i in range(N):
        A, B = map(int, input().split())
        # deadline, effort
        heapq.heappush(h, (B, A))

    days = 0
    for i in range(N):
        work = heapq.heappop(h)
        days += work[1]
        # print(days, work)
        if days > work[0]:
            print('No')
            return

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
d = dict()
for i in range(n):
    w, t = map(int, input().split())
    if t in d:
        d[t] = d[t] + w
    else:
        d[t] = w
d = sorted(d.items(), key=lambda x:x[0])
now = 0
ans = True
for x in d:
    t, w = x
    now = now + w
    if now > t:
        ans = False
        break
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
n = int(input())
d = dict()
for i in range(n):
    w, t = map(int, input().split())
    if t in d:
        d[t] = d[t] + w
    else:
        d[t] = w
d = sorted(d.items(), key=lambda x:x[0])
now = 0
ans = True
for x in d:
    t, w = x
    now = now + w
    if now > t:
        ans = False
        break
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
import sys

n = int(input())

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

need_t = 0
for b, a in abl:
    need_t += a
    if b < need_t:
        print("No")
        sys.exit()
        
print("Yes")

Submission status: Accepted

Solution code:
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([[2, 4], [1, 9], [1, 8], [4, 9], [3, 12]]), 'Yes')

    def test_2(self):
        self.assertEqual(think([[334, 1000], [334, 1000], [334, 1000]]), 'No')

    def test_3(self):
        self.assertEqual(think([[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]]), 'Yes')


def solve():
    list_of_a_and_b = read()
    result = think(list_of_a_and_b)
    write(result)


def read():
    n = read_int(1)[0]
    list_of_a_and_b = []
    for i in range(n):
        list_of_a_and_b.append(read_int(2))
    return list_of_a_and_b


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    data.sort(key=lambda x: (x[1], x[0]))
    current_time = 0
    for d in data:
        if current_time + d[0] > d[1]:
            return 'No'
        current_time += d[0]
    return 'Yes'


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Accepted

Solution code:
import sys

n = int(input())

dic = {}

for i in range(n):
  a, b = map(int,input().split())
  if not (b in dic.keys()):
    dic[b] =[]
    
  dic[b].append(a)
  
minute = 0
for k, arr in sorted(dic.items()):
  minute += sum(arr)
  if minute > k:
    print('No')
    sys.exit(0)
    
print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys
n = int(input())
a = [0] * n
#b = [0] * n
#print(a,b)
for i in range(n):
    a[i] = list(map(int,input().split()))

a.sort(key=itemgetter(1))
tmp = 0
for i in a:
    tmp += i[0]
    if tmp > i[1]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter
N = int(input())
l_2d = [list(map(int, input().split())) for i in range(N)]
A, B = l_2d_t = [list(x) for x in zip(*l_2d)]

z = [[a, b] for a,b in zip(A,B)]
z.sort(key=itemgetter(1))
time = 0
possible = True
for i in range(N):
  time += z[i][0]
  if time > z[i][1]:
    possible = False

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
al = [list([0] * 2) for _ in range(N)]

for i in range(N):
    a, b = map(int, input().split())
    al[i][0] = a
    al[i][1] = b
al.sort(key=lambda x:(x[1], x[0]))
ans = 'Yes'
t = 0
for i in range(N):
    t += al[i][0]
    if t > al[i][1]:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
#N=5
#A,B = [2,1,1,4,3],[4,9,8,9,12]
A,B = [],[]
for i in range(N):
    a,b = input().split()
    A.append(int(a))
    B.append(int(b))


import numpy as np
C = np.array([A,B])

C = C[:,C[1,:].argsort()]
A,B = C[0],C[1]
i=0
while(i<N):
    n=0
    #ind = i+n
    while((i+n<N) and (B[i]==B[i+n])):
        n += 1
    if(n>1):
        #print(n,i,A[i:i+n] )
        #pdb.set_trace()
        A[i:i+n] = A[i:i+n][::-1]
    i+=n
"""
print(A,B)
sum_ = 0
y=[]
b = []
for i in range(N):
    sum_ += A[i]
    y.append(sum_)
    b.append(B[i])
plt.plot(y)
plt.plot(b)
plt.show()
plt.close()"""
time = 0
hantei = 0
for i in range(N):
    time += A[i]
    if(time>B[i]):
        hantei = 1
        break
        
print("Yes") if hantei==0 else print("No")

Submission status: Accepted

Solution code:
N = int(input())
a = []
for i in range(N):
    ta, tb = map(int, input().split())
    a.append([ta, tb])
a = sorted(a, key=lambda x:(x[1], x[0]), reverse=True)
deadline = a[0][1]
for i in range(N - 1):
    deadline -= a[i][0]
    deadline = min(deadline, a[i + 1][1])
    if deadline < 0:
        print('No')
        exit()
deadline -= a[N - 1][0]
if deadline < 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
b = []
cnt = 0
for _ in range(n):
    a1,b1 = map(int,input().split())
    a.append(a1)
    b.append(b1)
c = sorted(zip(b,a))
for i in range(n):
    cnt += c[i][1]
    if cnt > c[i][0]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    J=[tuple(map(int,input().split())) for _ in range(n)]
    J.sort(lambda x:x[1])
    now=0
    for a,b in J:
        now+=a
        if(now>b):
            print("No")
            return
    print("Yes")
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
W=[]
for i in range(N):
    A, B = list(map(int, input().split()))
    W.append([A, B])
W.sort(key=lambda x:x[1])
Sum = 0
f = 0
for i in range(N):
    Sum = Sum+W[i][0]
    if Sum > W[i][1]:
        print("No")
        f = f+1
        break
if f == 0:
    print('Yes')

Submission status: Accepted

Solution code:
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li.sort(key=lambda x:(x[1],x[0]*(-1)))

hiniti = 0

for i in range(n):
    hiniti += li[i][0]
    if hiniti > li[i][1]:
        print("No")
        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])
#print(AB)
c=0
ans="Yes"
for a,b in AB:
    c+=a
    if c>b:
        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))

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

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

Submission status: Accepted

Solution code:
N = int(input())
C = [] #最遅入り時間
for i in range(N):
    a, b = map(int, input().split())
    C.append((a, b, i))
C.sort(key=lambda x:x[1])

t = 0
ans = 'Yes'
for i in range(N):
    if C[i][1] - C[i][0] < t:
        ans = 'No'
        break
    t += C[i][0]

print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq

n = int(input())
ab = []
for i in range(n):
  tmp = list(map(int, input().split()))
  job = (tmp[1], tmp[0])
  heapq.heappush(ab, job)

today = 0
for i in range(n):
  tmp = heapq.heappop(ab)
  today += tmp[1]
#  print(today)
  if today > tmp[0]:
#    print (-tmp[0])
    print('No')
    sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = []
B = []
A_and_B = {}
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

B_sort_index = sorted(range(len(B)), key=lambda k: B[k])

all_time = 0
for b in B_sort_index:
  all_time += A[b]
  if B[b] >= all_time:
    continue
  else:
    print("No")
    sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
A = []
B = []

job = {}
for _ in range(N):
  a, b = map(int, input().split())
  job.setdefault(b, []).append(a)
wa = 0
flag = 0
for k, v in sorted(job.items()):
  wa += sum(v)
  if k < wa:
    print("No")
    flag = 1
    break
if flag == 0:
  print("Yes")

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter, attrgetter
N = int(input())
AB = []
for _ in range(N):
  AB.append(tuple(map(int, input().split())))
AB.sort(key = itemgetter(1))

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

Submission status: Accepted

Solution code:
import math
import copy
import sys
import bisect
input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    #複数行の「1 2 3 4」型の入力を一配列に
    #x = sorted([list(map(int, input().split())) for _ in range(n)])
    n=int(input())
    x = sorted([list(map(int, input().split())) for _ in range(n)])
    x.sort(key=lambda y:y[1])
    time=0
    for i in range(n):
        time+=x[i][0]
        if time>x[i][1]:
            print("No")
            exit()
    print("Yes")


main()

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

Submission status: Accepted

Solution code:
import sys

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

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

for i in range(N):

    Sum += list[i][0]

    if Sum > list[i][1]:
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
ab = sorted(ab,key = itemgetter(1))
ab.insert(0,[0,0])
flag = 0
flag_2 = 0
for j in range(1,n+1):
  flag += (ab[j][1]-ab[j-1][1])-ab[j][0]
  if flag < 0:
    print("No")
    flag_2 = 1
    break
if flag_2 == 0:
  print("Yes")

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(1)

N = I()
AB = [LI() for _ in range(N)]

AB = sorted(AB, key=lambda x: x[1])
T = int(0)
for i in range(N):
    T += AB[i][0]
    if T>AB[i][1]:
        ans = -1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

num_list = []

for _ in range(n):
    nums = list(map(int, input().split()))
    num_list.append(nums)

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

count = 0

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

print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
L=[list(map(int,input().split())) for _ in range(N)]
s=0
p=True
L=sorted(L,key=lambda x: x[1])
for l in L:
    s+=l[0]
    if l[1]>=s:
        continue
    else:
        p=False
        break
print("Yes" if p else "No")

Submission status: Accepted

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

Submission status: Accepted

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

from operator import itemgetter

L.sort(key=itemgetter(1))

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
list1 = [list(map(int,input().split())) for i in range(n)]

list1.sort(key=itemgetter(1))
megalovania = 0
for i in range(n):
	megalovania += list1[i][0]
	if megalovania > list1[i][1]:
		print("No")
		exit()
print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
C = []*2*N
for i in range(N):
    a,b = map(int,input().split())
    C.append(b)
    C.append(a)
D = np.array(C).reshape(N,2).tolist()
D.sort()
time = 0
flag = 1
for i in range(len(D)):
    if time + D[i][1] > D[i][0]:
        flag = 0
        break
    else:
        time += D[i][1]

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = []*N
B = []*N
C = []*2*N
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(b)
    C.append(a)
D = np.array(C).reshape(N,2).tolist()
D.sort()
time = 0
flag = 1
for i in range(len(D)):
    if time + D[i][1] > D[i][0]:
        flag = 0
        break
    else:
        time += D[i][1]

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

S = sorted(S, key=itemgetter(1))

t = 0
flag = True
for i in S:
    if t+ i[0] > i[1]:
        print("No")
        flag = False
        break

    t += i[0]

if flag:    
    print("Yes")

Submission status: Accepted

Solution code:
def megalomania():
    n = int(input())
    tasks = []
    for i in range(n):
        tasks.append(tuple(map(int, input().split())))

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

    time = 0
    for a, b in tasks_sorted:
        time += a
        if time <= b:
            continue
        else:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    megalomania()

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

cur = 0
for i in range(N):
  dead, time = l[i]
  if(cur + time <= dead):
    cur += time
  else:
    print("No")
    exit()

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
jobs = sorted([[int(x) for x in input().split()] for _ in range(n)], key=lambda x: x[1])
t = 0
for a, deadline in jobs:
    t += a
    if t > deadline:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = list()

for i in range(n):
    x,y = map(int,input().split())
    a.append((x,y))
    
a.sort(key = lambda x : (x[1],x[0]))
    
c = 0
ch = 1
for i in range(n):
    if(c+a[i][0]>a[i][1]):
        ch = 0
        break
    else:
        c += a[i][0]
    
if(ch==0):
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
lis=[[int(i) for i in input().split()] for j in range(n)] 
for i in range(n):
  lis[i].reverse()
lis.sort()
a=0
b=0
ans=0
for i in range(n):
  a+=lis[i][1]
  b=lis[i][0]
  if a>b:
    ans=1
    break
if ans==1:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

l.sort(key=lambda x: x[1])
count = 0
for i in range(N):
    count += l[i][0]
    if not count <= l[i][1]:
        print('No')
        quit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

work = []

for _ in range(n):
    ai, bi = map(int, input().split())
    work.append([ai, bi])

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

deadline = 0
total = 0
success = True

for w in work:
    deadline = w[1]
    total += w[0]
    
    if deadline < total:
        success = False
        break

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

Submission status: Accepted

Solution code:
# D - Megalomania

import numpy as np

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

AB = sorted(AB, key = lambda x: x[1]) # 締め切りが早い順
A = np.array([AB[idx][0] for idx in range(N)])
C = A.cumsum()

for idx in range(N):
    if C[idx] > AB[idx][1]:
        print("No")
        exit()
        
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.sort(reverse=True)
cur = AB[0][0]
for ab in AB:
	a = ab[1]
	b = ab[0]
	cur = min(cur, b)
	cur -= a
if(cur >= 0):
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:
N = int(input())
arr = [list(map(int,input().split())) for _ in range(N)]
arr.sort(key=lambda x: x[1])
cnt = 0
for a,b in arr:
  cnt += a
  if cnt > b:
    flag = "No"
    break
  flag = 'Yes'

print(flag)

Submission status: Accepted

Solution code:
import sys
import heapq
n = int(input())
tasks = []
for i in range(n):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    heapq.heappush(tasks, (b, a))
_sum = 0
flg = True
for i in range(n):
    b, a = heapq.heappop(tasks)
    if _sum + a > b:
        flg = False
        break
    _sum += a
if flg:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

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

now = 0
flag = False
for l in L:
    now += l[0]
    
    if now  > l[1]:
        flag = True
        break


if flag:
    print('No')

else:
    print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l,key=itemgetter(1))
ct=0
for i in range(n):
  ct+=l[i][0]
  if ct>l[i][1]:
    print('No')
    sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
ans = 'Yes'
t = 0
n = int(input())
list_ab = [list(map(int, input().split())) for _ in range(n)]
# 期限の迫っている順に並べる
list_ab.sort(key=lambda val: val[1])

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

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter


def solve():
    t = 0
    for a, b in ab:
        t += a
        if t > b:
            return False
    return True


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

task.sort()

s = 0
ans = 'Yes'
for a, b in task:
    s += b
    if s > a:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
lst=[tuple(map(int,input().split())) for _ in range(N)]
lst_=sorted(lst,key=lambda x:x[1])
t=0
for n in range(N):
    t+=lst_[n][0]
    if t>lst_[n][1]:
        print("No")
        exit(0)
print("Yes")

Submission status: Accepted

Solution code:
import sys

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