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())
a = [[int(i) for i in input().split()] for i in range(n)]
a = sorted(a, key=itemgetter(1))
sum = 0
ans = 'Yes'
for i in range(n):
  sum += a[i][0]
  if sum > a[i][1]:
    ans = 'No'
    break
print(ans)

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

Submission status: Accepted

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

from operator import itemgetter

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

t = 0
ans = 'Yes'

for a, b in A:
    t += a
    if t > b:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

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

cumulative_times = []
t = 0
for job in jobs:
	t += job[0]
	cumulative_times.append(t)

flag = True
for job, c in zip(jobs, cumulative_times):
	if c > job[1]:
		flag = False

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 = 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())
li = []
for i in range(N):
    x, y = map(int, input().split())
    li.append([y, x])

time = 0
for i in sorted(li):
    time += i[1]
    if time > i[0]:
        print("No")
        quit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
l = [None]*N
s = []
for i in range(N):
    k = list(map(int,input().split()))
    if k[0]==k[1]:
        s.append(k)
        l[i] = [0,0]
    else:
        l[i] = k

if len(s)>1:
    print("No")
else:
    l = sorted(l, key=lambda x: x[1])
    cnt = 0
    if len(s)==1:
        cnt += s[0][1]

    flag = True
    for j in l:
        if j==[0,0]:
            continue
        else:
            cnt += j[0]
        if cnt>j[1]:
            print("No")
            flag = False
            break
    if flag:
        print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
ba = []
for i in range(n):
    a,b = inm()
    ba.append((b,a))
ba.sort()
sum = 0
for i in range(n):
    b,a = ba[i]
    sum += a
    if sum>b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

BA.sort()
t = 0
ans = 'Yes'
#print(BA)
for ba in BA:
    B = ba[0]
    A = ba[1]
    t += A
    if t > B:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append((a, b))

    A = sorted(A, key=lambda x: x[1])
    time = 0
    for a, b in A:
        time += a
        if time > b:
            return 'No'

    return 'Yes'


if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

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

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

Flag = False

for i in range(N):
    now += C[i][0]
    if now > C[i][1]:
        Flag = True
        break

if Flag == True:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
N = int(input().strip())
lines = sorted([list(map(int, line.strip().split())) for line in sys.stdin], key=lambda x:x[1])
now_time = 0
for l in lines:
  now_time += l[0]
  if now_time > l[1]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
AB = []
for n in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])
AB.sort(key=lambda x:x[1])
t = 0
c = 0
for i in AB:
    t += i[0]
    if t>i[1]:
        break
    c += 1
if c<len(AB):
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import numpy as np
import re


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


def main():
    N = input()
    AB = [inputs() for _ in range(int(N))]
    AB.sort(key=lambda x: x[1])
    time = 0
    for a, b in AB:
        time += a
        if time > b:
            return 'No'
    return 'Yes'


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
N=int(input())
kekka=[]
for i in range(N):
    A,B=map(int,input().split())
    kekka.append([B,A])
kekka=sorted(kekka)
#print(kekka)
hour=0
task=0
for i in range(N):
    hour=kekka[i][0]
    task+=kekka[i][1]
    if hour <task:
        print("No")
        break
    if i==N-1:
        print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
task = []
amount = 0
for i in range(n):
    a, b = [int(i) for i in input().split()]
    amount += a
    task.append([a, b])
task_1 = sorted(task, key=lambda x:(x[1], -x[0]))
limit = task_1[n-1][1]
frag = 0
now = 0
cnt = 0
if(amount > limit):
    frag = 1
else:
    for i in range(n):
        now += task_1[i][0]
        cnt += 1
        if(task_1[i][1] < now):
            frag = 1
        if(frag == 1):
            break
if(frag == 1):
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

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

# print(l)

curTime = 0
f = False

for i in l:
    curTime += i[0]

    if curTime > i[1]:
        f = True
        break


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

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    ABs = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
    ABs = sorted(ABs, key=lambda x: (x[1], x[0]))
    now = 0
    for A, B in ABs:
        now += A
        if B < now:
            print('No')
            return
    print('Yes')


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


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


now=0
for i in range(n):
    now+=b[i][0]
    if now>b[i][1]:
        print("No")
        quit()

print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())

l = list()
for n in range(N):
    N, M = map(int, input().strip().split())
    l.append([N, M])

l.sort(key=itemgetter(0), reverse=True)
l.sort(key=itemgetter(1))

current_time = 0
for n, m in l:
    current_time += n
    if current_time > m:
        ans = 'No'
        break
    else:
        ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

works.sort(key=lambda w: w[1])

t = 0
for w in works:
    t += w[0]
    if w[1] < t:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
X = [[int(x) for x in input().split()] for _ in range(N)]
X.sort(key=itemgetter(1))
sum = 0

for i in range(N):
    sum += X[i][0]
    if sum > X[i][1]:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
l = [[0,0] for i in range(n)]
for i in range(n):
    a,b = map(int,input().split())
    l[i][0],l[i][1] = b,a
l.sort()
c = 0
for i in range(n):
    c += l[i][1]
    if c <= l[i][0]:
        continue
    else:
        break
if i == n-1 and c <=l[i][0]:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

N = int(input())

w = []

limit = 0

for _ in range(N):

    ai, bi = map(int, input().split())
    w.append((ai, bi))

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

now = 0
for v in w:
    limit = v[1]
    now += v[0]
    if now > limit:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

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

lst.sort()
lst = lst + [[0, 0]]

time = lst[0][1]
i = 0
while i < N and time <= lst[i][0]:
    time += lst[i+1][1]
    i += 1

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

Submission status: Accepted

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

time = 0
for A, B in sorted(ABs, key=lambda x: x[1]):
    time += A
    if time > B:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

ABlist = []

for i in range(N):
    A, B = map(int, input().split())
    ABlist.append((A, B))

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

ans = "Yes"
Asum = 0

for i in ABlist:
    Asum += i[0]
    if(Asum > i[1]):
        ans = "No"
        break
    
print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import namedtuple

Task = namedtuple('Task', ('a', 'b'))

def main():
    n = int(input())
    tasks = []

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

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

def solve(tasks):
    t = 0
    for task in sorted(tasks, key=lambda t: t.b):
        t += task.a
        if t > task.b:
            return False
    
    return True


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

Submission status: Accepted

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

A_ = sorted(A,key=lambda x: x[1])
Sum = 0
for x in A_:
    Sum += x[0]
    if Sum > x[1]:
        print("No")
        sys.exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]
l.sort(key=lambda x:x[1])

s = 0
ind = len(l)
for i in range(len(l)):
    s += l[i][0]
    if (s > l[i][1]):
        ind = i
        break
 
if (ind == len(l)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())

ts = [tuple(map(int, input().split())) for _ in range(N)]
ts.sort(key=lambda t: t[1])

T = 0
for a, b in ts:
  T+=a
  if T>b:
    print('No')
    exit(0)

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

AB = []
for _ in range(N):
    ab = tuple(map(int, input().split()))
    AB.append((ab[1], ab[0]))
AB = sorted(AB)

t = 0
result = "Yes"
for ab in AB:
    t = t + ab[1]
    if t > ab[0]:
        result = 'No'
        break

print(result)

Submission status: Accepted

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

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

sum=0
for i in range(N):
  sum+=T[i][0]
  if sum>T[i][1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
N =int(input())
A = []
for i in range(N):
    a,b = map(int, input().split())
    A.append([a,b])
A.sort(key=lambda x:x[1])
tmp = 0
for t,up in A:
    if tmp + t > up:
        print('No')
        break
    tmp += t
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
T = []

for _ in range(N):
	a, b = map(int, input().split(' '))
	T.append((a, b))

T = sorted(T, key=lambda t: t[1])

s = 0
ok = True

for (t, d) in T:
	s += t
	if s > d:
		ok = False
		break

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

Submission status: Accepted

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

T = 0
for n in range(N):
  T += AB[n][0]
  T_limit = AB[n][1]
  if T > T_limit:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

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


def main():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    mod_ab = sorted(ab, key=lambda x: (x[1], x[0]))
    time = 0
    b_max = mod_ab[-1][1]

    for ai, bi in mod_ab:
        time += ai

        if time > b_max or time > bi:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = input()
AB = []
NGflag = 0
for i in range(N):
	a,b = map(int, raw_input().split())
	AB.append((a,b))
ABsort =sorted(AB,key = lambda x:x[1])
now = 0
for item in ABsort:
	now += item[0]
	if now > item[1]:
		NGflag = 1
		break
if NGflag == 0:
	print("Yes")
else:
	print("No")

Submission status: Accepted

Solution code:

import numpy as np
def acinput():
    return list(map(int, input().split(" ")))

N=int(input())

S=[]
a=[]
for i in range(N):
    tmp=acinput()
    S.append(tmp)


S=sorted(S,key=lambda x:x[1])
a=[]
b=[]
for ss in S:
    a.append(ss[0])
    b.append(ss[1])
acs=np.cumsum(a)

res="Yes"
for i in range(N):
    if acs[i]>b[i]:
        res="No"
        break

print(res)

Submission status: Accepted

Solution code:
n = int(input())

ab = []

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

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

flag = True
time = 0
for i in range(n):
    a, b = ab[i]
    time += b - a
    if time > b:
        flag = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
tmp = zip(B, A)
B, A = zip(*sorted(tmp))

total = 0
flag = False
for b, a in zip(B, A):
    total += a
    if total > b:
        flag = True
        break
if flag:
    print("No")
else:
    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])
s=0
ans='Yes'
for i in range(N):
    s += AB[i][0]
    if s > AB[i][1]:
        ans='No'
print(ans)

Submission status: Accepted

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

import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
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 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

N=INT()
AB=[]
for i in range(N):
    a,b=MAP()
    AB.append((a, b))

AB.sort(key=itemgetter(1))
time=0
for i in range(N):
    a,b=AB[i]
    time+=a
    if b<time:
        No()
        exit()
Yes()

Submission status: Accepted

Solution code:
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
T.sort(key=lambda x:x[1])
time=0
err=0
for i in range(N):
    time=time+T[i][0]
    if time>T[i][1]:
        err=1
        break
if time<=T[N-1][1] and err==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
# input
n = int(input())
o = []
for i in range(n):
    o.append(list(map(int, input().split())))
o.sort(key=itemgetter(1))
# calc
t = 0
for j in range(n):
    t += o[j][0]
    if t > o[j][1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
lst=sorted([list(map(int,input().split())) for i in range(n)],key=lambda x : x[1])
tmptime=0
hp=0
flag=True
for i in range(n):
    hp+=lst[i][1]-tmptime
    tmptime=lst[i][1]
    hp-=lst[i][0]
    if hp<0:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import math

n = int(input())
#a, b, c, d = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = input()
#list = list(s)

table2 = sorted(table, key=lambda x:(x[1]))
sum = 0
flag = 0


for i in range(n) :
    sum += table2[i][0]
    if (sum > table2[i][1]) :
        flag = 1


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

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    N = int(input())
    jobs = []
    for i in range(N):
        time_consume, deadline = map(int, input().split())
        jobs.append([deadline, time_consume])
    jobs = sorted(jobs)
    # print(jobs)
    time_ = 0
    for i in range(N):
        time_ += jobs[i][1]
        if (time_ <= jobs[i][0]):
            # 締め切りより時間が立っていなければ、
            pass
        else:
            print("No")
            break
    else:
        print("Yes")



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

#A,B= map(int,input().split())
#list(map(int,input().split()))
N = int(input())

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

ruiseki = [0]*(N+1)
for i in range(N):
    ruiseki[i+1] = ruiseki[i]+l[i][1]
for i in range(N):
    if l[i][0] < ruiseki[i+1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
# using main() makes code faster from the point of view of "access to variables in global name-space"
# def main():

# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from math import factorial
def factorize(n):
    """return the factors of the Arg and count of each factor
    
    Args:
        n (long): number to be resolved into factors
    
    Returns:
        list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
    """
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from operator import itemgetter 
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)

# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
    # evaluate reciprocal using Fermat's little theorem:
    # a**(p-1) is identical to 1 (mod p) when a and p is coprime
    return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
    if n <= 1:
        return [0,1][:n+1]
    else:
        inv_t = [0,1]
        for i in range(2, n+1):
            inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
        return inv_t
def modfactorial_list(n, p = MOD):
    if n == 0:
        return [1]
    else:
        l = [0] * (n+1)
        tmp = 1
        for i in range(1, n+1):
            tmp = tmp * i % p
            l[i] = tmp
        return l
def modcomb(n, k, fac_list = [], p = MOD):
    # fac_list = modfactorial_list(100)
    # print(modcomb(100, 5, modfactorial_list(100)))
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if len(fac_list) <= n:
        a = factorial(n) % p
        b = factorial(k) % p
        c = factorial(n-k) % p
    else:
        a = fac_list[n]
        b = fac_list[k]
        c = fac_list[n-k]
    return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
    return (a + b) % MOD
def modsub(a, b, p = MOD):
    return (a - b) % p
def modmul(a, b, p = MOD):
    return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
    return modmul(a, modpow(b, p-2, p))


# initialize variables and set inputs
#initialize variables
    # to initialize list, use [0] * n
    # to initialize two dimentional array, use [[0] * N for _ in range(N)]
# set inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
# calculate and output
    # output pattern
    # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6

# functions used
r = lambda: sys.stdin.readline().strip() #single: int(r()), line: map(int, r().split())
R = lambda: list(map(int, r().split())) # line: R(), lines: [R() for _ in range(n)]
R_t = lambda: tuple(map(int, r().split()))
Rmap = lambda: map(int, r().split())

# set inputs
N = int(r())
AB = [R_t() for _ in range(N)]
ABC = [(a,b,b-a) for a,b in AB]
ABC.sort(key=itemgetter(1))
time = 0
for a, b, c in ABC:
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")

# if __name__ == '__main__':
#     main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

from operator import itemgetter


N = int(input())


AB = [(0, 0, 0)]*N
for n in range(N):
    a, b = list(map(int, input().split()))
    AB[n] = (a, b, b-a) 
AB = tuple(sorted(AB, key = itemgetter(1)))

    
def main():
    tot = 0
    for i, ab in enumerate(AB):
        if tot <= ab[2]:
            tot+=ab[0]
        else:
            return print("No")
        #print(ab, tot)
    print("Yes")
                
                
            
            
                

    
if __name__ == '__main__':
    main()

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

t = 0
for A, B in l:
    t += A
    if t > B:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import numpy as np
N =int(input())
A =[]
B =[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
index = np.argsort(B)
time = 0
f = 0
for i in index:
    time += A[i]
    if time>B[i]:
        f = 1
        break
if f == 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(lambda: 0)
N = int(input())
for _ in range(N):
    a, b = map(int, input().split())
    d[b] += a
d_keys = list(d.keys())
d_keys.sort()
tmp_time = 0
flag = True
for i in range(len(d_keys)):
    tmp_time += d[d_keys[i]]
    if tmp_time > d_keys[i]:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

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.sort(key=lambda x:x[1])
#print(tasks)

cur = 0
c = True
for i in range(n):
    cur += tasks[i][0]
    if cur > tasks[i][1]:
        c = False

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

Submission status: Accepted

Solution code:
n = int(input())
w = {}
for i in range(n):
  a, b = map(int,input().split())
  if b in w:
    w[b] += a
  else:
    w[b] = a
sum = 0
w = sorted(w.items(), key=lambda x:x[0])
#print(w)
for i in range(len(w)):
  k = w[i][0]
  v = w[i][1]
  sum += v
  if sum > k:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:
def code_for_D(test=None):

    N = int(input())

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

    time_now = 0
    answer = 'Yes'

    for work in works:
        time_now += work[0]
        time_by = work[1]

        if time_now > time_by:
            answer = 'No'

    print(answer)


def main():
    code_for_D()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

s = "Yes"
time=0
for t, shime in allList:
    time += t
    if time > shime:
        s = "No"
print(s)

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

able = True
sum = 0

for i in range(N):
  sum += AB[i][0]
  if (sum > AB[i][1]):
    able = False
    break

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

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())

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

c = sorted(zip(a, b), key=itemgetter(1))
a, b = zip(*c)
a = list(a)
b = list(b)

for i in range(1, n):
  a[i] += a[i-1]

flag = True

for i in range(n):
  if a[i] > b[i]:
    flag = False
    break

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

Submission status: Accepted

Solution code:
def solve(J):
    t = 0
    J.sort(key=lambda x: x[0])
    J.sort(key=lambda x: x[1])
    for i in range(len(J)):
        t += J[i][0]
        if t > J[i][1]:
            return False
    return True


N = int(input())
Job = [list(map(int, input().split())) for _ in range(N)]
print("Yes") if solve(Job) else print("No")

Submission status: Accepted

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

nums = [0]
for i, t in enumerate(tasks):
    nums.append(nums[i]+t[0])
    if nums[i+1] > t[1]:
        print('No')
        quit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
task = []
for i in range(n):
    temp = list(map(int,input().split()))
    task.append(temp)
    
task = sorted(task, key=lambda x:(x[1],x[0]))
temp_time = 0
for i in range(n):
    if temp_time+task[i][0] <= task[i][1]:
        temp_time += task[i][0]
    else:
        print("No")
        sys.exit()
        
print("Yes")