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 operator import itemgetter
n = int(input())

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

abs=sorted(ab, key=itemgetter(1))

sum=0
check=0
for i in range(n):
    sum+=abs[i][0]
    if sum <= abs[i][1]:
        continue
    else:
        check=1
        break

if check == 0:
    print("Yes")
else:
    print("No")

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

Submission status: Accepted

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

    num_list = sorted(num_list, key=lambda x: x[1])
        
    time = 0
    for i in range(n):
        time += num_list[i][0]
        if time > num_list[i][1]:
            print('No')
            exit()

    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ab_list = list(list(map(int,input().split())) for i in range(n))
sort_list = sorted(ab_list, key=lambda x: x[1])
sum_time = sort_list[0][0]
for i in range(1,len(ab_list)):
  if sum_time <= sort_list[i-1][1]:
    sum_time += sort_list[i][0]
  else:
    print("No")
    break
else:
  if sum_time <= sort_list[-1][1]:
    print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    works = []
    for i in range(N):
        period, deadline = map(int, input().split())
        works.append((period,deadline))
    
    works.sort(key=lambda x:x[1])

    time = 0
    for period, deadline in works:
        time += period
        if time > deadline:
            print('No')
            return
    
    print('Yes')

    
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

worktime = 0
for work, limit in task:
  worktime += work
  if worktime > limit:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

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

t=0
C.sort(key=lambda x: x[1])

ans="No"
for i,item in enumerate(C):
  if item[0]+t<=item[1]:
    t += item[0]
  else:
    break
else:
  ans="Yes"
  
print(ans)

Submission status: Accepted

Solution code:
import itertools
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
from math import factorial

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60
MOD = 10 ** 9 + 7

#Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ここから書き始める
n = int(input())
ab = [()] * n
for i in range(n):
    a, b = map(int, input().split())
    ab[i] = (b, a)
ab.sort()
# print(ab_sorted)
time = 0
yes = True
# print("ab", ab)
for i in ab:
    time += i[1]
    # print("time =", time)
    if time > i[0]:
        yes = False
        break
if yes:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x:(x[1],x[0]))
 
t = 0
ans = 'Yes'
for a,b in AB:
    t += a
    if t <= b:
        continue
    else:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

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

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x:(x[1],x[0]))
 
t = 0
ans = 'Yes'
for a,b in AB:
    t += a
    if t <= b:
        continue
    else:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
AB.sort(key=lambda x:(x[1],x[0]))
 
t = 0
ans = 'Yes'
for a,b in AB:
    t += a
    if t <= b:
        continue
    else:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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

Submission status: Accepted

Solution code:
# D
import sys
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
time = 0
for work in ab:
    if time+work[0] <= work[1]:
        time+=work[0]
    else:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    n=int(input())
    ba=[]
    for i in range(n):
        a,b=map(int,input().split())
        ba.append((b,a))
    ba.sort()
    asum=0
    ans='Yes'
    for b,a in ba:
        asum+=a
        if asum>b:
            ans='No'
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
AB = []
sumJ = 0
maxK = 0
for i in range(N):
  a,b = map(int,input().split())
  AB.append([a,b])
AB = sorted(AB, key=itemgetter(1))
for j,k in AB:
  sumJ += j
  maxK = max(k,maxK)
  if sumJ > maxK:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

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

n = int(input())
ba = [list(map(int,input().split()[::-1])) for _ in range(n)]

ba.sort()

time = 0
for tmp in ba:
    b,a = tmp
    time += a
    if(b < time):
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

#締め切りが早い仕事から始める
a.sort(key=lambda x: x[1])

time = 0
ans = True
for i in a:
  time += i[0]
  if i[1] < time:
    ans = False
    break

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

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])
now = 0
for i in ab:
    if i[1] >= now + i[0]:
        now += i[0]
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

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

key = 0
ans = True
for i in range(n):
  if key + work[i][1]> work[i][0]:
    ans = False
    break
  key += work[i][1]

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

Submission status: Accepted

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

Submission status: Accepted

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

c = sum([i for i,j in ab])
abmax = max([j for i,j in ab])

ab.reverse()
ans = "Yes"
x = c + 0
for i,j in ab:
    if not x <= j:
        ans = "No"
        break
    x -= i

print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
AB = np.array([lr() for _ in range(N)])
AB = AB[np.argsort(AB[:, 1])]
A = AB[:, 0]
B = AB[:, 1]
bl = np.all(A.cumsum() <= B)
print('Yes' if bl else 'No')
#

Submission status: Accepted

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

res = "Yes"
time_sum = 0
for i in range(N):
  time_sum += AB[i][0]
  if time_sum > AB[i][1]:
    res = "No"
    break

print(res)

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.readline
from collections import Counter
from copy import deepcopy
from itertools import combinations
from operator import itemgetter

def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(tuple(map(int, input().split())))

    # 二つめの要素＝各タスクの締め切り時刻でソート。
    a.sort(key = itemgetter(1))
    # タスク処理時間の積算値をいれる変数
    time = 0
    for i in range(n):
        time += a[i][0]
        if time > a[i][1]:
            print('No')
            exit()
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
AB = [lr() for _ in range(N)]
AB.sort(key=lambda x: x[1])
answer = 'Yes'
time = 0
for i in range(N):
    if time + AB[i][0] > AB[i][1]:
        answer = 'No'
    time += AB[i][0]

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
5
2 4
1 9
1 8
4 9
3 12
'''

def solve(l):
	n = len(l)
	l = sorted(l)
	# print('l:',l)
	last = 0
	for i in range(n):
		last += l[i][1]
		if(last > l[i][0]):
			return 'No'
	return 'Yes'
	

N = int(stdin.readline())
L = []
for _ in range(N):
	a,b = list(map(int, stdin.readline().rstrip().split()))
	L.append([b,a])
ans = solve(L)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

now = 0
flag = 0
for i in range(n):
  now += l[i][0]
  if now > l[i][1]:
    flag = 1
    break

print("Yes" if flag == 0 else "No")

Submission status: Accepted

Solution code:
N = int(input())
P = [0]*N
#B = [0]*N
for i in range(N):
  P[i] = list(map(int, input().split()))
  
P.sort(key=lambda x: x[1])
t = 0
ans = 'Yes'
for p in P:
  t += p[0]
  if t > p[1]:
    ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
tasks = []
ans = 'Yes'

for i in range(N):
    t, d = (int(x) for x in stdin.readline().rstrip().split())
    tasks.append((t, d))

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

total = 0
for x, y in tasks:
    total += x
    if total > y:
        ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
H = []
for _ in range(N):
    A, B = map(int,input().split())
    H.append((B, A))
H.sort()
t = 0
for i in range(N):
    B, A = H[i]
    t += A
    if B < t:
        print("No")
        break 
    if i == N - 1:
        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])
for i in range(1,len(a)):
    a[i][0]+=a[i-1][0]
for i in a:
    if i[0]>i[1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=sorted([list(map(int,input().split())) for nd in range(n)],key=lambda x: x[1])
now=0
for a,s in l:
  if a+now>s:print("No");exit()
  now+=a
else:print("Yes")

Submission status: Accepted

Solution code:
ab = sorted([list(map(int,input().split())) for _ in range(int(input()))], key=lambda x:(x[1],x[0]))
time = 0
for l in ab:
  time += l[0]
  if time > l[1]:
    print("No")
    quit()
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],x[0]))
time = 0
for l in ab:
  time += l[0]
  if time > l[1]:
    print("No")
    quit()
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])
Atime = [0]
for i in range(N) :
    Atime.append(Atime[i]+AB[i][0])

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
jobs = []
for _ in range(n):
  a,b  = map(int,input().split())
  jobs.append((a,b))
  
jobs.sort(key = lambda x: x[1])
time = 0
for i in range(n):
  a,b = jobs[i]
  time += a
  if time <= b:
    continue
  else:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
list_score = [[] for i in range(n)]

for i in range(n):
    a = list_score[i]
    x, y = map(int, input().split())
    a.append(x)
    a.append(y)

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

score = 0
ans = "Yes"
for i, j in list_score:
    score += i
    if score > j:
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
work = []
for i in range(n):
    a,b = map(int,input().split())
    work.append([a,b])
work.sort(key = lambda x:x[1],)
time = 10000000000
for i in range(len(work)):
    x = work.pop()
    time = min(time,x[1])-x[0]
    if time < 0:
        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])

time = 0
for a, b in ab:
    time += a

    if time > b:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

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

lefttime = ab[0][1]
for a, b in ab:
    lefttime = min(lefttime, b)
    lefttime -= a
    
    if lefttime < 0:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

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

A.sort()

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

Submission status: Accepted

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

A.sort()

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

Submission status: Accepted

Solution code:
import sys
import operator
N = int(input())
tasks = []
time = 0
ans = "Yes"

for cmd in sys.stdin:
  a,b = map(int, cmd.strip("\n").split())
  tasks.append([a,b])
tasks.sort(key=operator.itemgetter(1))

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    L = [list(map(int,input().split())) for _ in range(n)]
    L.sort(key = lambda x: x[1])
    time = 0
    for a, b in L:
        time += a
        if time > b:
            print('No')
            return
    print('Yes')
main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    L = [list(map(int,input().split())) for _ in range(n)]
    L.sort(key = lambda x: x[1])
    now = 0
    for l in L:
        now += l[0]
        if now > l[1]:
            print('No')
            return
    print('Yes')
main()

Submission status: Accepted

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

x.sort(key=lambda x:(x[1],x[0]))
t=0
ans='Yes'
for i in range(n):
    if t+x[i][0]<=x[i][1]:
        t+=x[i][0]
    else:
        ans='No'
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
a=[]
for _ in range(int(input())):
    inp=[int(i) for i in input().split()]
    inp.reverse()
    a.append(inp)
a.sort()
t=0 ; flag=0
for i in a:
    t+=i[1]
    if t>i[0]:
        flag=1
        break
if flag==0: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

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

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

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


now = 0
for i in range(N):
    A,B = AB[i]
    if now+A <= B:
        now += A
    else:
        now = -1
        break
if now == -1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
# D - Megalomania

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

total = 0
ans = 'Yes'

for a, b in T:
    total += a
    if total > b:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

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

def main():
    current = 0
    for i in range(N):
        current += X[i][0]
        if current > X[i][1]:
            print('No')
            return
    print('Yes')
    return

main()

Submission status: Accepted

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

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

t = 0
for a, b in jobs:
    t += a
    if t > b:
        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 x: x[1])
# print(AB)
now = 0
ok = True
for necessary, deadline in AB:
    # print(now)
    # print(necessary, deadline)
    if now + necessary > deadline:
        ok = False
        break
    now += necessary

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

Submission status: Accepted

Solution code:
n = int(input())
info = []
ok = True
for _ in range(n):
    a, b = map(int, input().split())
    info.append([a, b])
info.sort(key=lambda x: x[1])
Sum = 0
for i in range(n):
    Sum += info[i][0]
    # print(Sum, info[i][1])
    if Sum > info[i][1]:
        ok = False

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

# print(info)

Submission status: Accepted

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

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

t = 0
for i in range(n):
  t += ab[i][0]
  if t > ab[i][1]:
    print('No')
    sys.exit(0)

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=sorted(ab, key=itemgetter(1,0))
#print(ab)

time=0
for todotime,deadline in ab:
    time += todotime
    if not (time <= deadline) :
        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])
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())
a,b = [],[]
d = dict()
s = set()
for i in range(n):
    bn,an = map(int,input().split())
    a.append(an)
    b.append(bn)
    if an not in d.keys():
        d.setdefault(an,bn)
    else:
        d[an] += bn

    s.add(an)

s = list(s)
s.sort()

counter = 0

for i in s:
    counter += d[i]
    if counter > i:
        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([A,B])
AB.sort(key=lambda x: x[1])
t=0
ans=True
for w in AB:
    t+=w[0]
    if t>w[1]:
        ans=False
print('Yes' if ans else 'No')

Submission status: Accepted

Solution code:
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
L=sorted(L,key=lambda x : x[1])
#last=L[0][1]
cnt=0
for i in range(N):
  cnt+=L[i][0]
  if L[i][1]<cnt:
    print('No')
    exit()
  #else:
    #last=L[i][1]
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()
time = 0
for b,a in l:
    if time+a > b:
        print("No")
        exit()
    else:
        time += a
print("Yes")

Submission status: Accepted

Solution code:
#131_D
n=int(input())
ab=[tuple(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])

tmp=0
flg=True
for a,b in ab:
    tmp+=a
    if tmp>b:
        flg=False
        break
print('Yes' if flg else 'No')

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    ab = [[0] * 2 for _ in range(n)]
    for i in range(n):
        ab[i] = list(map(int,ipti().split()))

    ab.sort(key=itemgetter(1))
    time = 0

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

T = sorted(T, key=lambda x:x[1])
t = 0
for a, b in T:
  t += a
  if t > b:
    print("No")
    quit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	ddd=[]
	for _ in range(n):
		a,b=IN()
		ddd.append([a,b])
	ddd=sorted(ddd, key=lambda vv : vv[1])
	cc=0
	for a,b in ddd:
		#print(cc,a,b)
		cc += a
		if cc > b:
			return 'No'
		
	return 'Yes'
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n = int(input())
BA = [[0, 0] for i in range(n)]
for i in range(n):
    BA[i][1], BA[i][0] = map(int, input().split())
ans = 'Yes'

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

job.sort(key = itemgetter(1))

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

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline())
m = map(int, sys.stdin.read().split())
ab = list(zip(m, m))

ab.sort(key=lambda x: x[1])
ans = 'Yes'
time = 0
for a, b in ab:
    time += a
    if time > b:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline())
Job = [None]*N
for i in range(N):
    Job[i] = tuple(map(int, stdin.readline().split()))[::-1]

Job.sort()

Now = 0
for i in range(N):
    Deadline = Job[i][0]
    Now += Job[i][1]
    if Now > Deadline:
        print("No")
        quit()

else:
    print("Yes")

Submission status: Accepted

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

T = sorted(T, key=lambda x:x[1])
t = 0
for a, b in T:
  t += a
  if t > b:
    print("No")
    quit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    AB=[0]*N
    for i in range(N):
        ab=list(map(int,input().split()))
        AB[i]=ab
    AB.sort(key=lambda x:x[1])
    t=0
    flag=True
    for i in range(N):
        t+=AB[i][0]
        if t>AB[i][1]:
            print("No")
            flag=False
            break
    if flag:
        print("Yes")
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  A[i][0], A[i][1] = A[i][1], A[i][0]
A.sort()
S = 0
p = "Yes"
for i in range(N):
  S += A[i][1]
  if S > A[i][0]:
    p = "No"
    break
print(p)

Submission status: Accepted

Solution code:
n = int(input())
ab = [[0] * 2 for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    ab[i][0], ab[i][1] = a, b
ab = sorted(ab, key=lambda x: x[1])
#print(ab)
time = 0
for task in ab:
    time += task[0]
    if time <= task[1]:
        #print(time, task[1])
        continue
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
AB={}
B=[]
base=0
answer="Yes"

for i in range(N):
    a,b=map(int,input().split())
    if b not in AB.keys():
        AB[b]=a
        B.append(b)
    else:
        AB[b]+=a
        
B=sorted(B)

for j in B:
    base+=AB[j]
    #print(base,j)
    if base>j:
        answer="No"

print(answer)

Submission status: Accepted

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

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

import sys
work = 0

for i in range(N):
    work += sortedAB[i][0]
    if work > sortedAB[i][1]:
        print('No')
        sys.exit()
        
print('Yes')

Submission status: Accepted

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

t = 0
ans = "Yes"

for a, b in sorted(task, key=lambda x: x[1]):
    t += a
    if t > b:
        ans = "No"
        break

print(ans)