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:
# coding: utf-8
n = int(input())
dic = []
for i in range(n):
    a, b = list(map(int, input().split()))
    dic.append({'task': i, 'duration': a, 'due': b})
dicsort = sorted(dic, key = lambda x: (x['due'], x['duration']))
completed = 0
result = True
for i in dicsort:
    completed += i['duration']
    if completed > i['due']:
        result = False
        break
if result:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    n = int(input())
    ab = [list(map(int, stdin.readline().split())) for i in range(n)]
    ab.sort(key=lambda x:x[1])
    now = 0
    cnt = 0

    for a, b in ab:
        now += a
        if now > b: break
    else:
        print("Yes")
        return 0
    print("No")


if __name__=="__main__": main()

Submission status: Accepted

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

time = 0
for i in range(N):
    A[i], B[i]= map(int, input().split())
    if A[i] > B[i]:
        print('No')
        quit()

index = sorted(range(N), key=lambda k: B[k])
for ind in index:
    if time + A[ind] > B[ind]:
        print('No')
        quit()
    else:
        time += A[ind]
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
SB = sorted(L, key=lambda x:x[1])
flg = 0
cnt = 0
for i in range(N):
    cnt += SB[i][0]
    if SB[i][1] < cnt:
        flg = 1
        break
if flg == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import itertools as itr

n = int(input())
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split())))
ab.sort(key=lambda x: x[1])
a = [x[0] for x in ab ]
b = [x[1] for x in ab ]
finished = list(itr.accumulate(a))
ans = 'Yes'
for i in range(n):
    if finished[i] > b[i]:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline

N = int(input())
A = [0]*N
work = 0
for i in range(N):
    A[i] = list(map(int, input().split()))
A.sort(key=itemgetter(0))
A.sort(key=itemgetter(1))

for i in range(N):
    work += A[i][0]
    if work > A[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)]
for z in range(n):
    l[z][0],l[z][1]=l[z][1],l[z][0]
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())

line=[]

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

line.sort()

s=0
t=0

for i in range(n):
    t=line[i][0]
    s+=line[i][1]
    if s>t:
        print('No')
        break
    if i==n-1:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a_b = [list(map(int, input().split())) for _ in range(N)]
a_b = sorted(a_b, key = lambda x: (x[1], x[0]))
sum_t = 0
flag = 0
for t, lim in a_b:
    sum_t += t
    if sum_t > lim:
        flag = 1
        break
if flag:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    arr = list(map(int,input().split()))
    a.append(arr)
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, heapq

def solve():
    input = sys.stdin.readline
    N = int(input())
    Q = []
    heapq.heapify(Q)
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(Q, (b, a))
    time = 0

    for i in range(N):
        b, a= heapq.heappop(Q)
        if time + a > b:
            print("No")
            break
        else:
            time += a

    else: print("Yes")



    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A, B = [], []
    for ix in range(N):
        a, b = LI()
        A.append(a)
        B.append((ix, b))
    B = sorted(B, key=lambda x: x[1])
    cur_t = 0
    ans = "Yes"
    for b in B:
        ix, b_dead = b
        cur_t += A[ix]
        if cur_t > b_dead:
            ans = "No"
            break
    print(ans)

main()

Submission status: Accepted

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

elapsed_time = 0
for AB in ABs:
    A = AB[0]
    B = AB[1]
    if elapsed_time + A > B:
        print('No')
        exit()
    elapsed_time += A

print('Yes')

Submission status: Accepted

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

total = 0
tf = True
for l in ls:
    total += l[0]
    if total > l[1]:
        tf = False
        break
if tf:
    print('Yes')
else:
    print('No')

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

Submission status: Accepted

Solution code:
N=int(input())
task=[list(map(int,input().split())) for _ in range(N)]
s_t=sorted(task,key=lambda x: x[1])
total=0
flag=True
for i in s_t:
    total+=i[0]
    if total>i[1]:
        flag=False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = list(map(int, input().split()))
n = n[0]

ab=[]

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

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

#print(ab)

le = 0

flag = "Yes"

for i in range(n):
    le += ab[i][0]
    if(le>ab[i][1]):
        flag = "No"
        
print(flag)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter


def solve(tasks):
    tasks.sort(key=itemgetter(1))
    t = 0
    for a, b in tasks:
        t += a
        if t > b:
            return False
    return True


n = int(input())
tasks = [tuple(map(int, line.split())) for line in sys.stdin]
print('Yes' if solve(tasks) else 'No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
task = []
for i in range(N):
    task += [ [int(x) for x in input().split()] ]

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

time, i = task[0][0], 0
while time <= task[i][1]:
    i += 1
    if i >= N:  break
    time += task[i][0]

if i == N:    print('Yes')
else:   print('No')

Submission status: Accepted

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

for _ in range(n):
    c,d = map(int,input().split())
    tasks.append([d,c])
tasks.sort()
maxday = tasks[-1][0]
worked = 0
for i in range(n):
    day = tasks[i][0]
    cost = tasks[i][1]
    if day - worked < cost :
        print("No")
        exit()
    else:
        worked += cost
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
works = list()
safe = True
for _ in range(N):
    works.append(list(map(int, input().split())))

works.sort(key=lambda x: x[1])
cumsum = 0

for work in works:
    cumsum += work[0]
    if cumsum > work[1]:
        safe = False
        break

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC131 D
import sys
import math

N = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())
#print(N)

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

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

time = 0
time_over = 0
for i in range(N):
    time += work[i][0]
    if(time > work[i][1]):
        time_over = 1
        break

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

Submission status: Accepted

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

arr = sorted(arr)

sum = 0
for i in range(N):
    sum += arr[i][1]
    if sum > arr[i][0]:
        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.sort(key=lambda x: x[1])
worktime = 0
ndat = 0
for i in range(N):
    worktime += AB[i][0]
    if worktime > AB[i][1]:
        print('No')
        break
    ndat += 1
if ndat == N:
    print('Yes')

Submission status: Accepted

Solution code:
import sys

N = int(input())

AB = [0] * N

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

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

time = 0
for i in AB:
    A, B = i
    time += A
    if time > B:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
d = [list(map(int,input().split())) for i in range(N)]
#締切昇順でsort
d.sort(key=lambda x : x[1])
ret = "Yes"
cur_task = 0
for ab in d:
    cur_task+=ab[0]
    if cur_task > ab[1]:
        ret = "No"
        break
print(ret)

Submission status: Accepted

Solution code:
N=int(input())

wlist = []
for i in range(N):
  a,b=map(int,input().split())
  wlist.append((b,a))
  
wlist.sort()
#print(wlist)

ok = True
time = 0
for i in range(N):
  b,a=wlist[i]
  time += a
  if time > b:
    ok = False
    break
    
if ok:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
job = [[int(_) for _ in input().split()] for __ in range(N)]
job.sort(key=lambda x:x[1])

t =0
for j in job:
    t += j[0]
    if t > j[1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
itv = []
for i in range(N):
  itv.append(list(map(int, input().split())))
itv.sort(key=lambda x: x[1])
ans = 0
t = 0
for i in range(N):
  if (t <= itv[i][1]-itv[i][0]):
    ans += 1
    t += itv[i][0]
if ans == N:
  print ("Yes")
else:
  print ("No")

Submission status: Accepted

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

s=0
possible=True
for a, b in sorted(AB, key=lambda x:x[1]):
    s+=a
    if s>b:
        possible = False
        break

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

Submission status: Accepted

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

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

T=0
for e in x:
    T+=e[0]
    if e[1]<T:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:

def get_input():
    N = int(input())
    AB = [tuple(map(int,input().split(" "))) for i in range(N)]
    return N,AB

def solve(N,AB):
    sortedAB = sorted(AB,key=lambda x:x[1])
    sum_of_work = 0 
    flag = True  
    for a,b in sortedAB:
        sum_of_work += a 
        if sum_of_work > b :
            flag = False 
            break
    print("Yes" if flag else "No")

#N,AB = case1()
#solve(N,AB)
#N,AB = get_input()
solve(*get_input())

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))
N = int(input())

A, B = [0]*N, [0]*N
for i in range(N):
    A[i], B[i] = inpl()

T = sorted([(B[i], A[i]) for i in range(N)])

t = 0
for i in range(N):
    b, a = T[i]
    if b < t+a :
        print("No")
        break
    t += a
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = []
for _ in range(N):
  a, b = map(int, input().split())
  W.append([a, b])
s = 0 
for a, b in sorted(W, key=lambda x: x[1]):
  s += a
  if s > b:
    print('No')
    quit()
print('Yes')

Submission status: Accepted

Solution code:
import sys, fractions

readline = sys.stdin.readline

N = int(readline())
AB = [list(map(int, readline().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(0)

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

AB = [(-1, -1)] * N

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

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

enable = True
now = 0

for a, b in AB:
    if (now + a) <= b:
        now += a
    else:
        enable = False
        break

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

Submission status: Accepted

Solution code:


N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
           
time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

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

print(result)

Submission status: Accepted

Solution code:
N = int(input())

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

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

tt = 0
flag = False
for tk in tasks:
    tt += tk[0]
    if tt > tk[1]:
        flag = True
        break

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

Submission status: Accepted

Solution code:

import sys
N = int(input())
ab = []
for i in range(N):
    a, b = map(int, input().split())
    ab.append((b, a))
ab=sorted(ab, reverse = True)
time = ab[0][0]
flag = True
for i in range(N):
    b, a = ab[i]
    if ab[i][0]<time:
        time = b-a
    else:
        time -=a
    
if time>=0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
b=np.array([ab[i-1][1] if i>0 else 0 for i in range(n+1)])
ruisekiA=np.zeros(n+1)
for i in range(n):
    ruisekiA[i+1]=ruisekiA[i]+ab[i][0]
# print(ab)
# print(b)
# print(ruisekiA)
if len(ruisekiA[ruisekiA>b])==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())

works = []

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

works = sorted(works, key=lambda w: w[1])

deadtime = works[-1][1]

t = 0
ok = True
for w in works:
    if t + w[0] <= w[1]:
        t += w[0]
    else:
        ok = False
        break


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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

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

def solve(N: int, A: "List[int]", B: "List[int]"):
    #s = sorted([(b - a, i ) for i, (a, b) in enumerate(zip(A, B))])
    s = sorted([(b, i ) for i, (a, b) in enumerate(zip(A, B))])

    t = 0
    for _, i in s:
        a, b = A[i], B[i]
        t += a
        if b < t:
            return 'No'

    return 'Yes'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    result = solve(N, A, B)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
score = 0
flag = 1
n = int(input())
task = []
for i in range(n):
  task.append(list(map(int,input().split())))
t = sorted(task, key=lambda x:x[1])
for i in range(n):
  score += t[i][0]
  if score > t[i][1]:
    print('No')
    flag = 0
    break
if flag == 1:
  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])
now = 0
ans = 'Yes'

for i in range(N):
    now += AB[i][0]
    if now <= AB[i][1]:
        pass
    else:
        ans = 'No'

print(ans)

Submission status: Accepted

Solution code:

def main():
    buf = input()
    N = int(buf)
    BA = []
    for i in range(N):
        buf = input()
        buflist = buf.split()
        BA.append((int(buflist[1]), int(buflist[0])))
    BA.sort()
    elapsed = 0
    for x in BA:
        elapsed += x[1]
        if elapsed > x[0]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = input()
N = int(N)
s = [[ int(i) for i in input().split()] for i in range(N)]
time = 0
hoge = "Yes"
s = sorted(s, key=lambda s:s[1])
for i in s:
    time += i[0]
    if time > i[1]:
        hoge = "No" 
        break

print(hoge)

Submission status: Accepted

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

# bについてソート
ab = sorted(ab, key=lambda x: x[1])
sumNeed = 0
for item in ab:
    sumNeed += item[0]
    if sumNeed > item[1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
AB = [[int(x) for x in input().split()] for i in range(N)]
AB = sorted(AB, key=itemgetter(1, 0))

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

Submission status: Accepted

Solution code:
N = int(input())

lis = sorted([list(map(int, input().split()))[::-1] for _ in range(N)])

time = 0
flag = 1
for d, t in lis:
    time += t
    if time > d:
        flag = 0
        
print(['No', 'Yes'][flag])

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--


def f(AB):
    s = 0
    for a, b in sorted(AB, key=lambda x:x[1]):
        s += a

        if s > b:
            return 'No'

    return 'Yes'


def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for i in range(N)]
    print(f(AB))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
t = [list(map(int, input().split())) for i in range(N)]
t = sorted(t, key=lambda x:x[1])
acc = 0
for time, limit in t:
     acc += time
     if acc > limit:
         print('No')
         break
else:
    print('Yes')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    tasks = []
    for i in range(N):
        tasks.append(list(map(int, input().split())))
    tasks.sort(key=lambda x: x[1])
    t = 0
    for task in tasks:
        t += task[0]
        if t > task[1]:
            print('No')
            return
    print('Yes')
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())

tasks=[]

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

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

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

Submission status: Accepted

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

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


now = 0
for k, v in items:
    if now + k <= v:
        now += k
        continue
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
from sys import exit
INF = 10**21
N = int(input())
AB = [0 for i in range(N)]

for i in range(N):
    AB[i] = [int(n) for n in input().split()]
AB = sorted(AB, key=lambda x: x[0])
AB = sorted(AB, key=lambda x: -x[1])

now = AB[0][1]
for i in range(len(AB)):
    now = min(AB[i][1], now)
    now -= AB[i][0]
if now < 0:
    print("No")
    exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
W = []
for i in range(N):
    A,B = map(int,input().split())
    W.append([B,A])
W.sort()
time = 0
State = "Yes"
for i in range(N):
    time += W[i][1]
    if W[i][0] < time:
        State = "No"
        break
print(State)

Submission status: Accepted

Solution code:
n = int(input())
job = {}
for i in range(n):
    a, b = map(int, input().split())
    job[i] = (a, b)
job = sorted(job.items(), key=lambda k: k[1][1], reverse=True)
t = 1000000000
for k, v in job:
    c, d = v
    t = min(t, d) - c
if t < 0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
pairs = [[int(s) for s in input().split()] for _ in range(N)]
pairs.sort(key=lambda tup: tup[1])

acc = 0
for (a, b) in pairs:
    acc += a
    if acc > b:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

import sys
from operator import itemgetter

n = int( sys.stdin.readline() )
tm = dict()
for _ in range(n):
    a,b = [ int(x) for x in sys.stdin.readline().split() ]
    tm[b] = tm.get(b,0) + a
#
s = 0
ans = 'Yes'
for b,a in sorted(tm.items(),key=itemgetter(0)):
    s += a
    if s>b:
        ans='No'
        break
#
print( ans )

Submission status: Accepted

Solution code:
import numpy as np
import sys

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N = int(input())
    A = np.empty((N, 2))
    for i in range(N):
        A[i,:] = InputToInt()
    A = A[np.argsort(A[:, 0])]
    A = A[np.argsort(A[:, 1])]
    T = 0
    for i in range(N):
        T+=A[i, 0]
        if T > A[i, 1]:
            print('No')
            sys.exit()
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
li = [ [int(it) for it in input().split()] for i in range(N) ]
li.sort( key=lambda x:x[1] )
#print (li)
s = 0
flag = True
for a,b in li:
    s += a
    flag = flag and s<=b
    #print (s,b,s<=b)
print ( "Yes" if flag else "No" )

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
dt = [None] * n
for i in range(n):
    a, b = map(int, input().split())
    dt[i] = [b, a]
dt.sort()
t = 0
ans = True
for b, a in dt:
    if t + a > b:
        ans = False
    t += a
print(['No', 'Yes'][ans])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print("Yes")

Submission status: Accepted

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

from operator import itemgetter

def solve(n,arr):
	sarr1 = sorted(arr, key=itemgetter(1))
	cur = 0
	# print(sarr1)
	for i in range(n):
		t = sarr1[i]
		cur = cur + t[0]
		# print(cur, t[1])
		if cur > t[1]:
			return 'No'
	return 'Yes'

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

ans = solve(n,arr)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())						# 5

A=[]
for i in range(N):
	a,b = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7
	A.append([a,b])

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

ans="Yes"
a_sum=0
for i in range(N):
	a=B[i][0]
	b=B[i][1]
	
	a_sum+=a
	if a_sum>b:
		ans="No"
		break


print(ans)

Submission status: Accepted

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

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

x = 0
p = True
for c in C:
    x += c[0]
    if x > c[1]:
        p = False
        break
print('Yes' if p else 'No')

Submission status: Accepted

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

l.sort()
tmp = 0
for i in range(N):
    tmp += l[i][1]
    if tmp > l[i][0]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = int(input())
    ltask = []
    for i in range(N):
        a, b = map(int, input().split())
        ltask.append([a, b])

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

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

    print(ans)

solve()

Submission status: Accepted

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

from operator import itemgetter

AB.sort(key = itemgetter(1))

cost = 0

ans = 'Yes'
for a,b in AB:
    cost += a
    if cost > b:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
from operator import itemgetter

N = int(stdin.readline().rstrip().split()[0])
AB = []
for i in range(N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    AB.append((a,b))

AB = sorted(AB, key=itemgetter(1))
Frag = "Yes"
time=0
for a,b in AB:
    time += a
    if time>b:
        Frag="No"
        break

print(Frag)

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
flag = True
for i in range(n):
    cur += L[i][1]
    if cur > L[i][0]:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    C = [LIST() for i in range(N)]
    C.sort(key=lambda x:x[1])
    sum = 0
    for i in range(N):
        sum += C[i][0]
        if sum > C[i][1]:
            No()
            exit()
    Yes()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def solve():
  N = readInts()[0]
  tasks = [tuple(readInts()) for _ in range(N)]
  tasks.sort(key=lambda x: x[1], reverse=True)

  t = tasks[0][1] - tasks[0][0]
  if t < 0:
    return False

  for i in range(1, N):
    if t > tasks[i][1]:
      t = tasks[i][1]
    t -= tasks[i][0]
    if t < 0:
      return False

  return True

def main():
  ans = solve()
  if ans:
    print("Yes")
  else:
    print("No")

if __name__ == "__main__":
  main()