Problem:


Score: 400 points

Problem Statement

Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.

Let the current time be time 0. Kizahashi has N jobs numbered 1 to N.

It takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.

Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.

Can Kizahashi complete all the jobs in time? If he can, print Yes; if he cannot, print No.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i, B_i \leq 10^9 (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
.
.
.
A_N B_N

Output

If Kizahashi can complete all the jobs in time, print Yes; if he cannot, print No.

Sample Input 1

5
2 4
1 9
1 8
4 9
3 12

Sample Output 1

Yes

He can complete all the jobs in time by, for example, doing them in the following order:

Do Job 2 from time 0 to 1.

Do Job 1 from time 1 to 3.

Do Job 4 from time 3 to 7.

Do Job 3 from time 7 to 8.

Do Job 5 from time 8 to 11.

Note that it is fine to complete Job 3 exactly at the deadline, time 8.

Sample Input 2

3
334 1000
334 1000
334 1000

Sample Output 2

No

He cannot complete all the jobs in time, no matter what order he does them in.

Sample Input 3

30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720

Sample Output 3

Yes



Sample input:
5
2 4
1 9
1 8
4 9
3 12


Sample output:
Yes

Submission status: Accepted

Solution code:

from collections import defaultdict
d=set()
a=defaultdict(list)
n = int(input())
for i in range(n):
    h,m=list(map(int,input().split()))
    a[m].append(h)
    d.add(m)
t=0
r=0

for i in sorted(d):
    for j in a[i]:
        t+=j
    if t>i:
        r=1
        break
if r==1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n =  int(input())
    ls = []
    for _ in range(n):
        a, b = map(int, input().split())
        ls.append([b,a])
    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: Accepted

Solution code:
def main():
    n =  int(input())
    ls = []
    for _ in range(n):
        a, b = map(int, input().split())
        ls.append([b,a])
    ls = sorted(ls)
    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: Accepted

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

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    jobs = []
    for i in range(n):
        a,b = map(int,ipt().split())
        jobs.append((b,a))
    jobs.sort()
    t = 0
    for bi,ai in jobs:
        t += ai
        if bi < t:
            print("No")
            exit()

    print("Yes")
    return None

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
ab = [[int(i) for i in input().split()] for _ in range(n)]

ab.sort()
ab.sort(key=itemgetter(1))
t = 0
for a, b in ab:
    t += a
    if t > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

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

t = 0
for i in range(N):
    t += times[i][0]
    if t > times[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.sort(key=lambda x:x[1])
time=0
for i in range(N):
    time+=AB[i][0]
    if time>AB[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
lst = [0] * n
for i in range(n):
  lst[i] = tuple(map(int, input().split()))
lst.sort(key=itemgetter(1))
t = 0
for i in range(n):
  t += lst[i][0]
  if t > lst[i][1]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

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

for ab in AB:
    sum_t += ab[0]
    if sum_t > ab[1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

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

Submission status: Accepted

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

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

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:
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x:(x[1], x[0]))

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

abl.sort()
curr = 0
for b,a in abl:
    curr += a
    if curr > b:
        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 = sorted(ab, key=lambda x:(x[1], -x[0]))
count = 0
for i in range(n):
    count += ab[i][0]
    if count > ab[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:

import datetime
from decimal import Decimal, ROUND_DOWN
import heapq
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
n = int(input())
# w = list(map(int, input().split()))
#A = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
# a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
ab = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
ab_sorted = sorted(ab, key=lambda x: x[1])
# print(ab_sorted)

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

Submission status: Accepted

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

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 = sorted(data, key = lambda x: x[1])
time = 0
ans = "Yes"
for i in range(n):
    if time + data[i][0] > data[i][1]:
        ans = "No"
    time += data[i][0]
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [list(map(int, input().split())) for _ in range(n)]
    a.sort(key=lambda x: x[1], reverse=True)
    lim = float("inf")
    for p, q in a:
        if q < lim:
            lim = q
        lim -= p
    if 0 <= lim:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
g = []
for _ in range(n):
  a, b = map(int, input().split())
  g.append([a,b])
g = np.array(g)
g = g[np.argsort(g[:, 1])]
a = 0
for i,j in g:
  a+=i
  if a>j:
    print('No')
    exit(0)
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    a_b = []
    for _ in range(n):
        a_b.append(LI())
    a_b.sort(key=lambda x: x[1])
    t = 0
    for d in a_b:
        t += d[0]
        if t > d[1]:
            print("No")
            sys.exit()
    print("Yes")

if __name__ == '__main__':
    main()

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

t=0

for a,b in ab:
    t+=a

    if t>b:
        print('No')
        exit(0)

print('Yes')

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
L = []
for i in range(N):
    A,B = I()
    L.append([B,A])
L.sort()
cnt = 0
for i in range(N):
    cnt += L[i][1]
    if cnt > L[i][0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

X.sort(key=lambda x: x[1])
t = 0
ans = "No"
for a, b in X:
    if t + a > b:
        break
    t += a
else:
    ans = "Yes"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

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

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

time=0
work=0
count=0

for i in range(N):
    time=brr[i][1]
    work+=brr[i][0]
    if work<=time:
        count+=1
if count==N:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

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

max_B = max(B)
sum_A = sum(A)

if (sum_A > max_B):
    print('No')
    exit()
else:
    count = 0
    for i in range(N):
        count += L[i][0]

        if (count > L[i][1]):
            print('No')
            exit()
        else:
            continue

    print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
l=[]
dead=0
time=0
for i in range(n):
    a,b=map(int,input().split())
    l.append([b,a])
l.sort()
f=True
for i in l:
    dead=i[0]
    time+=i[1]
    if time>dead:
        print('No')
        f=False
        break
if f:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
AB = list()
for _ in range(N):
    ab = list(map(int, input().split()))
    ab.reverse()
    AB.append(ab)
AB.sort()
#print(AB)

at = 0
flag = False

for i in range(N):
    bt = AB[i][0]
    at += AB[i][1]
    #print(at, bt)
    if at > bt:
        flag = True
        break

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

Submission status: Accepted

Solution code:
N = int(input())
task = [0]*N
for i in range(N):
    a, b = map(int,input().split())
    task[i] = (b, a)
task.sort()

#print(task)

time = 0
for t in task:
    limit, required = t
    if time + required > limit:
        print('No')
        break
    time += required
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
total_time = 0

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

    if total_time > ab[i][1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
C = []
for i in range(N):
  A, B = map(int, input().split())
  C.append([B, A])
C.sort()
a = 0
ans = 'Yes'
for i in range(N):
  if a + C[i][1] <= C[i][0]:
    a += C[i][1]
  else:
    ans = 'No'
    break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
lst = []
for i in range(N):
    A,B = map(int,input().split())
    lst.append([B,A])
    
if N == 1:
    print("Yes" if B - A >= 0 else "No")
    exit()
    
lst.sort()  
left = lst[0][0] - lst[0][1]

for i in range(1,N):
    left = left + (lst[i][0] - lst[i-1][0])
    left -= lst[i][1]
    if left < 0:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
job = []
for _ in range(N):
    a,b = map(int,input().split())
    job.append((a,b))
from operator import itemgetter
job_sort = sorted(job, key = itemgetter(1))
import sys
time = 0
for i in range(N):
    time += job_sort[i][0]
    if time>job_sort[i][1]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    from operator import itemgetter
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    now = 0
    for a, b in AB:
        if now + a <= b:
            now += a
        else:
            print("No")
            return
    print("Yes")

main()

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = i()
time = []

for i in range(S):
    a = l()
    a.reverse()
    time.append(a)

time.sort()

pl = 0

for i in range(S):
    pl += time[i][1]
    if pl > time[i][0]:
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
li=[rl() for _ in range(n)]
li.sort(key=lambda x: x[1])
sum_=0
for i in range(n):
    sum_+=li[i][0]
    if sum_>li[i][1]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
l=[]
for i in range(n):
    l.append(lmp())
l=sorted(l,key=lambda x:x[1])
t=0
for i in range(n):
    t+=l[i][0]
    if t>l[i][1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
list=[list(map(int,input().split())) for _ in range(n)]
list1=sorted(list, key=lambda x:x[1])
t=0
for i in range(n):
  t+=list1[i][0]
  if not t<=list1[i][1]:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:
def myfunc(e):
  return e[1]
nb = int(input())
liste=[]
for loop in range(nb):
  liste += [[int(x) for x in input().split()]]
liste.sort(key=myfunc)
def mm():
  somme = 0
  for loop in range(len(liste)):
    somme += liste[loop][0]
    if somme>liste[loop][1]:
      return "No"
  return "Yes"
print(mm())

Submission status: Accepted

Solution code:
N = int(input())
C = {}

for i in range(N):
  a, b = map(int,input().split())
  if b in C.keys():
    C[b] += a
  else:
    C[b] = a
    
time = 0
D = sorted(C.items())

for i in range(len(D)):
  time += D[i][1]
  if time > D[i][0]:
    print('No')
    break
else:
  print('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])
AB.sort(key=lambda x: x[1])
sum = 0
for a,b in AB:
    sum += a
    if sum > b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
n=int(input())
ab=[]
for i in range(n):
  AB=[int(x) for x in input().rstrip().split()]
  ab.append(AB)
# ab=sorted(ab,key=lambda x :x[0])
ab=sorted(ab,key=lambda x :x[1])

time=0
for a,b in ab:
  if time+a<=b:
    time+=a
  else:
    print("No")
    sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys
n=int(input())
ab=[]
for i in range(n):
  AB=[int(x) for x in input().rstrip().split()]
  ab.append(AB)
ab=sorted(ab,key=lambda x :x[0])
ab=sorted(ab,key=lambda x :x[1])

time=0
for a,b in ab:
  if time+a<=b:
    time+=a
  else:
    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],-x[1]))

total = 0
for a, b in ab:
    total += a
    if total <= b:
        continue
    else:
        print("No")
        exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
apple = []
for _ in range(n):
    a, b = map(int, input().split())
    apple.append([b, a])
apple = sorted(apple)
count = 0
s = 0
for i in apple:
    if count + i[1] <= i[0]:
        s += 1
        count += i[1]
    else:
        s = 0
        break
print("Yes" if s==n else "No")

Submission status: Accepted

Solution code:
n=int(input())
t=[]
for i in range(n):
  at,bt=map(int,input().split())
  t.append([bt,at])
t.sort()
temp=0
for i in range(n):
  temp=temp+t[i][1]
  if temp>t[i][0]:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a_li = [[0]*2 for i in range(n)]
for i in range(n):
    a_li[i][1],a_li[i][0] = map(int,input().split())
a_li.sort()
time = 0
for i in range(n):
    time += a_li[i][1]
    if time > a_li[i][0]:
        print("No")
        exit()
print("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])
AB.sort(key=lambda x: x[1])
cumsum = 0
for a, b in AB:
    cumsum += a
    if cumsum > b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())

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

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

time=0
finished=True
for i in range(len(d_sorted)):
    time+=d_sorted[i][1]
    if time>d_sorted[i][0]:
        finished=False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
ba = []
now = 0
ans = "Yes"

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

for i in range(n):
    now += ba[i][1]
    
    if ba[i][0] < now:
        ans = "No"
        break
        
print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
t = 0
ls = [list(map(int,input().split())) for _ in range(n)]
ls = sorted(ls,key=lambda x:x[1])
for i in range(n):
    if ls[i][1]-t < ls[i][0]:
        print("No")
        sys.exit()
    else:
        t += ls[i][0]
print("Yes")

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read


def main():
    N, *AB = map(int, read().split())
    T = [0] * N
    for i, (a, b) in enumerate(zip(AB[::2], AB[1::2])):
        T[i] = [b, a]

    T.sort()

    ok = True
    sum_a = 0
    for b, a in T:
        sum_a += a
        if sum_a > b:
            ok = False
            break

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

    return


if __name__ == '__main__':
    main()

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], x[0]))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

t = 0
ans = 'Yes'

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

Submission status: Accepted

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

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

    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    n = int(input())
    a_b = [list(map(int, input().split())) for i in range(n)]
    a_b = sorted(a_b, key=lambda x: x[1])

    time_space = 0
    for i in range(len(a_b)):
        if i == 0:
            time_space = a_b[i][1] - a_b[i][0]
        else:
            time_space = a_b[i][1] - a_b[i - 1][1] - a_b[i][0] + time_space

        if time_space < 0:
            print("No")
            return

    print("Yes")


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """5
2 4
1 9
1 8
4 9
3 12"""
        output = """Yes"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3
334 1000
334 1000
334 1000"""
        output = """No"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """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"""
        output = """Yes"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

Solution code:
n=int(input())
num=[]
def ap(num1):
    num.append(num1)
for i in range(n):
    ap(list(map(int,input().split())))
num2=0
str1= lambda val: val[1]
num.sort(key=str1)
ans=0
for i in range(n):
    num2+=num[i][0]
    if num2>num[i][1]:
        ans=1
        break
if ans==1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
job = [list(map(int, input().split())) for _ in range(N)]
job.sort(key=lambda x: x[1])
time = 0
FLG = True

for need, limit in job:
    time += need
    if time > limit:
        FLG = False
        break

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

Submission status: Accepted

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

n = int(input())

readline = sys.stdin.readline

d = {}

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

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

s = 0
for t, w in d_sorted:
    s += w
    if s > t:
        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.sort()
time = 0
for b, a in ab:
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter

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

count = 0
Work = True
for i in range(n):
    if count + l[i][0] > l[i][1]:
        Work = False
        break
    else:
        count += l[i][0]

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

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:
#from statistics import median
import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
AB = [readInts() for _ in range(n)]
#print(AB)
AB = sorted(AB,key = lambda x:x[1])
time = 0
for i in range(n):
    if time + AB[i][0] <= AB[i][1]:
        time += AB[i][0]
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

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

t = 0
for i in range(n):
    t += l[i][0]
    if t > l[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.sort(key=lambda i: i[1])
t = 0
for i in ab:
  t += i[0]
  if t > i[1]:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

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

import sys

a.sort(key=lambda x: x[1])
sum=a[0][0]
for i in range(n-1):
  if sum>a[i][1]:
    print("No")
    sys.exit()
  sum=sum+a[i+1][0]
if sum>a[n-1][1]:
  print("No")
  sys.exit()
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])
now = 0
for i in range(n):
    now += l[i][0]
    if(now > l[i][1]):
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
ab=[[0]*2 for ii in range(n)]
for ii in range(n):
	ab[ii][1],ab[ii][0]=map(int,input().split())

#ab = sorted(ab, reverse=True, key=lambda x: x[1])  #[1]に注目してソート
ab.sort(reverse=True)
#print(ab)
r=ab[0][0]
for ii in range(n):
  r=min(ab[ii][0],r)-ab[ii][1]
  if r<0:
    print("No")
    exit()

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

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

time = 0
for a, b in data:
    time += a
    if (time > b):
        print('No')
        exit()
    else:
        pass

print('Yes')

Submission status: Accepted

Solution code:
#直感を証明できなかった

n = int(input())
l = []
for i in range(n):
    a,b = map(int, input().split())
    l.append((b, a)) #終了時間、工数
l = sorted(l) #終了時間が速い順に並べる

def check(l):
    t = 0 #現時刻
    for end, worktime in l:
        t += worktime
        if t > end:
            return 'No'
            break
            
    return 'Yes'
print(check(l))