Problem:


Score: 400 points

Problem Statement

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

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

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

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

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

Constraints

All values in input are integers.

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

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

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
.
.
.
A_N B_N

Output

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

Sample Input 1

5
2 4
1 9
1 8
4 9
3 12

Sample Output 1

Yes

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

Do Job 2 from time 0 to 1.

Do Job 1 from time 1 to 3.

Do Job 4 from time 3 to 7.

Do Job 3 from time 7 to 8.

Do Job 5 from time 8 to 11.

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

Sample Input 2

3
334 1000
334 1000
334 1000

Sample Output 2

No

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

Sample Input 3

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

Sample Output 3

Yes



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


Sample output:
Yes

Submission status: Accepted

Solution code:
n = int(input())
task = [[0 for i in range(2)] for j in range(n)]
frag = True
total = 0
for i in range(0, n):
    task[i][0], task[i][1] = map(int, input().split())
task = sorted(task, key=lambda x: x[1])

for i in range(n):
    total += task[i][0]
    if total > task[i][1]:
        frag = False

if frag == True:
    print("Yes")
if frag == False:
    print("No")

Submission status: Accepted

Solution code:
import sys
N = int(input())

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

pa, pb = (0, 10**9)
for a, b in sorted(a_b_list, key=lambda x: x[1]):
    pa += a
    pb = b
    if pb < pa:
        print('No')
        sys.exit(0)

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
sche = []
for i in range(n):
    a,b = map(int,input().split())
    sche.append((b,a))
sche.sort(reverse = True)
now = 1e18
for dead,ti in sche:
    if(dead < now):
        now = dead
    now -= ti

if now < 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
works = [[int(i) for i in input().split()] for _ in range(N)]
elapsed = 0

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

for work in works:
    time, deadline = work
    if elapsed + time <= deadline:
        elapsed += time
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
tensai = []
for i in range(n):
    a,b = map(int,input().split())
    tensai.append(b * 10000000000 + a)
tensai.sort()
time = 0
ans = "Yes"
for i in range(n):
    time += tensai[i] % 10000000000
    deadline = tensai[i] // 10000000000
    if time > deadline:
        ans = "No"
        break
    else:
        continue
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

t = 0
for v in ab:
    t += v[0]
    if t > v[1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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


sumtime = 0
flg = 0
for i in range(N):
    if(sumtime + Data[i][0] <= Data[i][1]):
        sumtime += Data[i][0]
    else:
        flg += 1
        break

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

Submission status: Accepted

Solution code:
num_lines = int(input())
if num_lines<1 or num_lines>2*10**5:
	print ('Illegal')
	exit()
a=[]
for i in range(num_lines):
	x,y=map(int,input().split(" "))
	if x<1 or y <=0 or y>10**9:
		print ('Illegal')
		exit()
	a.append([y,x,i])
a.sort()
r='Yes'
s=0
for i in range(num_lines):
	s+=a[i][1]
	if(s>a[i][0]):
		r='No'
		break;
print(r)

Submission status: Accepted

Solution code:
sortsecond = lambda val:val[1]
n = int(input())
l = []
t=0
for _ in range(n):
    a,b = map(int,input().split())
    l.append((a,b))
l.sort(key=sortsecond)
i=0
while(i<n):
    t+=l[i][0]
    if t>l[i][1]:
        print("No")
        break
    if i==n-1:
        print("Yes")
    i+=1

Submission status: Accepted

Solution code:
n = int(input())
x = [[int(i) for i in input().split()] for i in range(n)]
x.sort(key = lambda x: x[1])
total = 0
flag = 0
for i in range(n):
    if x[i][1]-total >= x[i][0]:
        total += x[i][0]
    else:
        flag = 1
        break
if flag == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from operator import itemgetter

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

total = 0
work.sort(key=itemgetter(1))

flag = True
for [a, b] in work:
    total = total + a
    if total > b:
        flag = False
        break

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

Submission status: Accepted

Solution code:

n = int(input())
a = []
i = 0
while i < n:
    a.append(list(map(int, input().split())))
    i += 1

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

i = 0
t = 0
while i < n:
    t += a[i][0]
    if t > a[i][1]:
        break
    i += 1

print("Yes" if i >= n else "No")

Submission status: Accepted

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

time = 0
flg = "Yes"
for b,a in elist:
    time = time + a
    if time > b:
        flg = "No"
        break

print(flg)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

ABs = []
for _ in range(N):
    ABs.append([int(j) for j in input().split()])

ABs = sorted(sorted(ABs, key=lambda x: x[0], reverse=True), key=lambda x: x[1])
t = 0
for i, AB in enumerate(ABs):
    t += AB[0]
    if t > AB[1]:
        print('No')
        break

    if i == N-1:
        print('Yes')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

N = read_int()[0]
AB = [read_int() for _ in range(N)]

def solve():
    AB.sort(key=lambda x: x[1])
    ans = True
    res = 0
    for i in range(N):
        res += AB[i][0]
        if res > AB[i][1]:
            ans = False
            break
    return "Yes" if ans else "No"

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
work = []

n = int(input())

for _ in range(n):
    work.append(tuple([int(x) for x in input().split()]))

# print(work)

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

# print(work_sorted_by_b)

sum_a = 0
for t in work_sorted_by_b:
    sum_a += t[0]
    if sum_a > t[1]:
        print('No')
        exit(0)

print('Yes')

Submission status: Accepted

Solution code:
import numpy as np
from collections import defaultdict
from functools import reduce

# s = input()
n = int(input())
# A = list(map(int, input().split()))
tasks = []
for i in range(n):
    a, b = map(int, input().split())
    tasks.append((b, a, i))

tasks.sort()

current = 0

for b, a, _ in tasks:
    current += a
    if current > b:
        break
else:
    print("Yes")
    exit()
print("No")

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
from operator import itemgetter

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

l.sort(key=itemgetter(1))
t = 0
for i in l:
    t += i[0]
    if t > i[1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
T = [tuple(map(int, input().split())) for _ in range(n)]
T.sort(key=lambda pair: pair[1])

time = 0

for a, b in T:
    time += a
    if time > b:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
import fractions

if __name__ == '__main__':
  n = int(input())
  work_list = []
  for i in range(n):
    a, b = map(int, input().split(" "))
    work_list.append((a, b))
      
  work_sorted = sorted(work_list, key=lambda x:x[1])
  total_work = 0
  success = "Yes"
  for key, value in work_sorted:
    total_work = total_work + int(key)
    if total_work > value:
      success = "No"
      break

  print (success)

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

    for ai, bi in mod_ab:
        time += ai

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

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n):
    task.append([int(j) for j in input().split()])

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

ans = "Yes"
cur = 0
remaining = 0
for i in task:
    remaining += i[1] - cur - i[0]
    if remaining < 0:
        ans = "No"
        break
    cur = i[1]

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())

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

cur = 0
can = True
for t, lmt in wl:
    cur += t
    if cur > lmt:
        can = False
        break
print('Yes' if can else 'No')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

t = 0
for a,b in L:
   t += a
   if (t>b):
      break;

print('Yes' if (t<=b) else 'No')

Submission status: Accepted

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

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

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

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

t = 0
flag = True
for i in range(N):
    t += q[i][0]
    if t > q[i][1]:
        flag = False
        break

if flag:
    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])

# accumerate a
for i, (a, _) in enumerate(ab):
    if i == 0:
        continue
    ab[i][0] = ab[i-1][0] + a

if all(ab[i][0] <= ab[i][1] for i in range(n)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = input()
jobs = []
for i in range(int(N)):
  t = input().split()
  t = [int(i) for i in t]
  jobs.append(t)

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

time = 0
flag = 0
for  i in range(int(N)):
  time +=  int(jobs[i][0])
#  print(time)
 # print(jobs[i][1])
  if time > int(jobs[i][1]):
    flag = 1
    break
if flag == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

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

def solve(N: int, W: "Tuple[int, int]"):
    W = sorted(sorted(W, key=lambda work: work[0], reverse=True), key=lambda work: work[1])
    t = 0
    for i in range(N):
        t += W[i][0]
        if t > W[i][1]:
            return NO
    return YES


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    W = [(int(), int())] * (N)  # type: "Tuple[int, int]"
    for i in range(N):
        a = int(next(tokens))
        b = int(next(tokens))
        W[i] = (a, b)
    print(solve(N, W))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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


time = 0
for t, deadline in job:
    time += t
    if time > deadline:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

def solve():
  sum_cost = 0
  for task in sorted_tasks:
    sum_cost+=task[0]
    if(task[1]<sum_cost):
      return False
  return True

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

Submission status: Accepted

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

Submission status: Accepted

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

a_b_list_kai = sorted(a_b_list_kai,key = lambda x:x[1])
limit = 0
result = 0
sum_task = 0
for x in a_b_list_kai:
    sum_task += x[0]
    limit = max(limit,x[1])
    if sum_task > limit:
        result = 1

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

Submission status: Accepted

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

elapsed_time = 0
possible = True
for job in jobs:
  if elapsed_time + job[0] <= job[1]:
    elapsed_time += job[0]
  else:
    possible = False
    break

if possible:
  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.sort(key=lambda x:x[1])
p = ab.pop()
suma = 0
for i in range(N-1):
    suma += ab[i][0]
    if suma > ab[i][1]:
        print("No")
        exit()
    
print("Yes" if suma+p[0]<=p[1] else "No")

Submission status: Accepted

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

Submission status: Accepted

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

time = 0
able = True

for i in range(N):
    time += listA[i][0]
    if time > listA[i][1]:
        able = False
        break
if able == True:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
N = int(readline())
T = []
S = 0
for i in range(N):
    a, b = map(int, readline().split())
    T.append((b, a))
    S += a
T.sort(reverse=1)
cur = 0
while cur < N:
    t, v = T[cur]; cur += 1
    if t < S:
        print("No")
        break
    S -= v
    while cur < N and t == T[cur][0]:
        S -= T[cur][1]
        cur += 1
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
N = int(input())
List = []
for i in range(N):
    tmp_a,tmp_b = map(int,input().split())
    List.append([tmp_b,tmp_a])
List.sort()
Sum_a= 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=[]
b=[]
time=0
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
bsort=np.sort(b)
bsoeji=np.argsort(b)
for i in range(n):
    time=a[bsoeji[i]]+time
    if time>bsort[i]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
jobL = []
index=0
while index < n:
    a, b = map(int, input().split())
    jobL.append([b, a])
    index+=1
jobL.sort()
timeCounter=0
index2=0
while index2 < len(jobL):
    timeCounter+=jobL[index2][1]
    if timeCounter <= jobL[index2][0]:
        index2+=1
    else:
        break
if index2 == len(jobL):
    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.sort(key = lambda AB:AB[1])
sum = 0
flag = 0
for i in range(len(AB)):
    sum += AB[i][0]
    if sum > AB[i][1]:
        flag = 1

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

Submission status: Accepted

Solution code:
N = int(input())
L = []
count = 0
flag = 0
for i in range(N):
    L.append(list(map(int, input().split())))

L.sort(key = lambda x:x[1] )
for i in range(N):
    count += L[i][0]
    if L[i][1] < count:
        print("No")
        flag = 1
        break

if flag == 0:
    print("Yes")
#print(N)
#print(L)

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys

n=int(input())
ls=[]
work=lim=0
i=0

for i in range(n):
    a,b=map(int,input().split())
    ls.append([a,b])
ls=sorted(ls,key=itemgetter(1))

for i in range(n):
    #print(i)
    work+=ls[i][0]
    #print(work,i)
    lim=ls[i][1]
    #print(lim,i)

    if lim<work:
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
AB = sorted([list(map(int,input().split())) for _ in [0]*N],key=lambda x:x[1])
T=0
for A,B in AB:
  T+=A
  if T>B:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
ab = [[int(x) for x in  input().split(" ")] for _ in range(n)]

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

t = 0

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

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
tasks = []
for i in range(N):
  A, B = list(map(int, input().split()))
  tasks += [[A, B]]
tasks = sorted(tasks, key=itemgetter(1))

minutes = 0
flag = True
for i in range(N):
  minutes += tasks[i][0]
  if minutes > tasks[i][1]:
    flag = False
    break
    
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
AB = [(0,0)]*N

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

AB.sort(key=itemgetter(1,0))

t = 0
flag = True

for a,b in AB:
    t += a
    if b < t:
        flag=False
print("Yes") if flag 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 x : x[1])

flag = True
time = 0

for i in range(n):
    time += works[i][0]
    if works[i][1] < time:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())

ab = []

for _ in range(n):

	ab.append(list(map(int, input().split())))
	

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

# print(ab)


limit = 0

work = 0

fail = 0


for i in range(n):

	limit = ab[i][1]

	work += ab[i][0]

	if work > limit:

		fail = 1

		break


if fail == 1:

	print("No")

else:

	print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    T = [ tuple( map( int, input().split())) for _ in range(N)]
    T = sorted(T,key=lambda x:x[1])
    time = 0
    ans = "Yes"
    for i in range(N):
        time += T[i][0]
        if time > T[i][1]:
            ans = "No"
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    T = [ tuple( map( int, input().split())) for _ in range(N)]
    T = sorted(T,key=lambda x:x[1])
    time = 0
    ans = "Yes"
    for i in range(N):
        time += T[i][0]
        if time > T[i][1]:
            ans = "No"
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    T = [ (0,0)]*N
    for i in range(N):
        a, b = map( int, input().split())
        T[i] = (b,a)
    T.sort()
    time = 0
    ans = "Yes"
    for i in range(N):
        time += T[i][1]
        if time > T[i][0]:
            ans = "No"
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    T = [ (0,0)]*N
    for i in range(N):
        a, b = map( int, input().split())
        T[i] = (b,a)
    T.sort()
    time = 0
    ans = "Yes"
    for i in range(N):
        time += T[i][1]
        if time > T[i][0]:
            ans = "No"
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, = list(map(int, input().split()))
d = {}
for i in range(N):
  ai,bi = list(map(int, input().split()))
  if bi in d:
    d[bi].append(ai)
  else:
    d[bi] = [ai]
B = list(d.keys())
B.sort()
ret = 'Yes'
s = 0
for b in B:
  s += sum(d[b])
  if s>b:
    ret = 'No'
print(ret)

Submission status: Accepted

Solution code:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n,m = ips()
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
a = []
for i in range(n):
    b = iprow()
    a.append([b[1],b[0]])
a.sort()
sumtime = 0
for i in range(n):
    sumtime += a[i][1]
    if sumtime > a[i][0]:
        j(0)
j(1)

Submission status: Accepted

Solution code:
N=int(input())
work=[None]*N
for i in range(N):
    work[i]= list(map(int, input().split()))
work=sorted(work,key=lambda work:work[1])
time=0
flag=0
for i,j in work:
    time += i
    if time > j:
        print("No")
        flag=1
        break
if flag==0:
    print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
a = []
b = []
time_tmp = 0
ans = True
N = int(input())
for i in range(N):
    atmp, btmp = (int(x) for x in input().split())
    a.append(atmp)
    b.append(btmp)
b_sort = np.argsort(b)
for i in range(N):
    work_num = b_sort[i]
    time_tmp += a[work_num]
    if time_tmp > b[work_num]:
        ans = False
if ans:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

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

time = 0


for a, b in AB:
    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 i in range(N)]

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

Submission status: Accepted

Solution code:
x = int(input())
tuple_works = [0 for i in range(x)]
for i in range(x):
    a = input().split()
    tuple_works[i] = (int(a[1]), int(a[0]))
tuple_works=sorted(tuple_works)
time = 0
is_over = False
for i in range(len(tuple_works)):
    time += tuple_works[i][1]
    if time > tuple_works[i][0]:
        print("No")
        is_over = True
        break
if not is_over:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

a = [0]*N
b = [0]*N

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

ab = list(zip(a,b))
quickwork = sorted(ab, key=lambda x: x[1])

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

Submission status: Accepted

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

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 x: x[1], reverse=False)

flag = TabError
spend_time = 0
for i in range(len(works)):
    spend_time += works[i][0]
    if spend_time > works[i][1]:
        flag = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n = int(input())

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

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

job = 0
for sl in sortedLst:
    job += sl[0]
    if job > sl[1]:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

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

can = 1
curtime = 0
for task in tasks:
    curtime += task[0]
    if curtime > task[1]:
        can = 0
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N=int(input())
    work=[]

    for i in range(N):
        W=list(map(int,input().split()))
        work.append(W)
    
    work.sort(key=lambda x:x[1])
    result=0
    flg=0

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

Submission status: Accepted

Solution code:
N=int(input())
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB,key = lambda x:x[1])
S=0
flag=0
for i in range(N):
    S+=AB[i][0]
    if S> AB[i][1]:
        print("No")
        flag=1
        break
if flag == 0:
    print("Yes")