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

a= int(input())
task = []
for i in range(a):
    task.append(list(map(int,input().split())))
task.sort(key=itemgetter(1))

now = 0
flag = 0
for i in range(a):
    now += task[i][0]
    if now > task[i][1]:
        flag =1
if flag == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

N = int(input())

past_time = 0
flag = True

data = []

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

for dd in data:
    A, B = dd[1], dd[0]
    past_time += A
    if past_time > B:
        flag = False
        break

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
ab = []

for i in range(N):
  ab.append(tuple(map(int, input().split())))

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

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

Submission status: Accepted

Solution code:
n=int(input())
AB=[list(map(int,input().split())) for i in range(n)]
#print(AB)
AB.sort(key=lambda ab:ab[1])
#print(AB)
time=0
ans="Yes"

for i in range(n):
    time+=AB[i][0]
    if(time>AB[i][1]):
        ans="No"
        break

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.zeros((N,2))
for i in range(N):
    A[i] =  np.array(list(map(int,input().split())))

B = A[np.argsort(A[:,1])]
x = 0
for i in range(N):
    x += B[i,0]
    y = B[i,1]
    if x > y:
        print('No')
        break
    else:
        if i == N-1:
            print('Yes')
            break

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

s = 0
result = True
for v in l:
  s += v[0]
  if s > v[1]:
    result = False
    break

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
ab = np.zeros((n, 2))

for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    ab[i, 0] = a_tmp
    ab[i, 1] = b_tmp

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

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

print("Yes")

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())

#memo = [0 for _ in range(int(2*1e5)+1)]
memo = {}

for _ in range(N):
	A,B = [int(s) for s in input().split(' ')]
	if B in memo:
		memo[B] += A
	else:
		memo[B] = A

s = 0
flg = True
key = list(memo.keys())
key = sorted(key)
for i in range(len(key)):
	s += memo[key[i]]
	if s > key[i]:
		flg = False
		break
if flg:
	print('Yes')
else:
	print('No')

Submission status: Accepted

Solution code:

n = int(input())
ab = []
for i in range(n):
    line = input().split()
    tmp = []
    tmp.append(int(line[0]))
    tmp.append(int(line[1]))
    ab.append(tmp)
    
ab = sorted(ab, key=lambda x: x[1])
t = 0
pos = True
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        pos = False
        break
if not pos:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
def sol(inp=input):
    n=int(inp())
    lines=[list(map(int,inp().split())) for _ in range(n)]
    lines=sorted(lines,key=lambda l:l[1])
    
    for i in range(n-1):
        lines[i+1][0]+=lines[i][0]

    return('Yes' if all(l[0]<=l[1] for l in lines) else 'No')

print(sol())

Submission status: Accepted

Solution code:
#coding:utf-8
import numpy as np
N = int(input())
ls = []
for n in range(N):
  a,b= map(int,input().split())
  ls.append([a,b])
ls = np.array(ls)
idx = np.argsort(ls[:,1])
ls = ls[idx]
sm = 0
for a,b in ls:
  sm += a
  if sm > b:
    print("No")
    exit()
print ("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
class Megalomania:
    def __init__(self):
        N = int(input())
        self.T = []
        for i in range(N):
            self.T.append([int(n) for n in input().split()])

    def main(self):
        sum_time = 0

        for task in sorted(self.T, key=lambda x: x[1]):
            sum_time += task[0]
            if sum_time > task[1]:
                print("No")
                return

        print("Yes")


megalomania = Megalomania()
megalomania.main()

Submission status: Accepted

Solution code:
N = int(input())

time = [0] * N

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


# 締め切り順
time.sort(key=lambda A : A[1])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

N = int(input())
tasks = []

fin = 0
for _ in range(N):
    A, B = map(int, input().split())
    fin = max(fin, B)
    heapq.heappush(tasks, (-B, A, B))

now = fin

while len(tasks)>0:
    _, time, deadline = heapq.heappop(tasks)
    now = min(deadline, now)
    now -= time

if now >= 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        for i in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        tokens = lines[0].split(" ")
        n = int(tokens[0])

    ab_list = []
    for i in range(1, n+1):
        tokens = lines[i].split(" ")
        a = int(tokens[0])
        b = int(tokens[1])
        ab_list.append((a, b))

    return (n, ab_list)


def solve(n, ab_list):


    ab_list.sort(key = lambda e: e[1])

    sum = 0
    result = "Yes"
    for i in range(n):
        e = ab_list[i]
        sum = sum + e[0]
        if sum > e[1]:
            result = "No"
            break

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D
if __name__=='__main__':
    N = int(input())
    AB = []
    worktime = 0
    answer = 'Yes'
    for i in range(N):
        a,b= map(int,input().split())
        AB.append((a,b))
    AB.sort(key=lambda x:x[1])
    for i in range(N):
        worktime +=AB[i][0]
        if worktime > AB[i][1]:
            answer = 'No'
            break
    print(answer)

Submission status: Accepted

Solution code:
import sys
N = int(input())
li = [None] * N
for i in range(N):
  li[i] = list(map(int,input().split()))
li = sorted(li, key = lambda x:x[1])

t = 0
for l in li:
  t += l[0]
  if t > l[1]:
    print("No")
    sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
N = int(stdin.readline().rstrip())
ab = [[None] * 2] * N
work = np.array(ab)
# print(work)
for i in range(N):
    input = stdin.readline().split()
    work[i][0], work[i][1] = int(input[0]), int(input[1])
# print(work)
# print(np.argsort(work[:,1]))
work_sort_b = work[np.argsort(work[:,1])]
# print(work_sort_b)

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

Submission status: Accepted

Solution code:
N = int(input())
ls = []
for i in range(N):
    ls.append(list(map(int,input().split())))
sls = sorted(ls,key=lambda x:x[1])
#print(sls)
time = 0
ans = 'Yes'
for v in sls:
    time += v[0]
    if time > v[1]:
        ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
S=[[i for i in map(int,input().split())] for _ in range(n)]
S=sorted(S, key=lambda x: x[1])
Sum=0
#dp=[[0 for __ in range(2)] for _ in range(n)]
for i in range(n):
  Sum += S[i][0]
  if Sum > S[i][1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
import sys
from collections import deque
stdin = sys.stdin

def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
N = ii()
infos = [ tuple(li()) for i in range(N) ]
infos.sort(key=lambda x:x[1])
def do(infos):
    works = deque()
    time = 0
    used = 0
    for t, e in infos:
        time += t
        works.append( (t, e) )
        while works and time >= works[0][1]:
            deadline = works[-1][1]
            lt, le = works.popleft()
            if deadline < time:
                return "No"

    return "Yes"
print(do(infos))

Submission status: Accepted

Solution code:
N = int(input())
works = []
for i in range(0, N):
	works.append(list(map(int, input().split())))
works.sort(key = lambda v: v[1])
now = 0
for i in range(0, N):
	now += works[i][0]
	if works[i][1] < now:
		print('No')
		break
	if i == N-1:
		print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
l = []
for i in range(n):
	l.append(list(map(int,input().split())))
l.sort(key=itemgetter(1))
t=0
for pair in l:
	t+=pair[0]
	if(t>pair[1]):
		print("No")
		exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
ab_ls = []
for i in range(n):
    ab_ls.append(list(map(int, input().split())))
ab_ls.sort(key=lambda x:x[1])
hoge = 0
result = True
for i in ab_ls:
    hoge = hoge + i[0]
    if hoge > i[1]:
        result = False
if result:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda xs: xs[1])
t = 0
for ab in AB:
    t += ab[0]
    if t > ab[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
#listA = []
#listB = []
listC = []
while True:     
  try:         
    #a, b = map(int,input().split())
    #listA.append(a)
    #listB.append(b)
    listC.append(list(map(int,input().split())))
  except:         
    break; 
#print(listA)  
#print(listB)
#print(listC)
#print(sum(listA))
#print(max(listB))
listC.sort(key=lambda x:(x[1],x[0]))
#print(listC)
time = 0
ans = "Yes"
for i in range(N):
  time += listC[i][0]
  if time <= listC[i][1]:
    continue
  else:
    ans = "No"
    break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
AB = []
for i in range(N):
    A, B = map(int, input().split())
    AB.append([A,B])
AB_list = AB
AB_list.sort(key=lambda x:x[0])
AB_list.sort(key=lambda x:x[1])
flag = True
task = 0
for i in range(N):
    task += AB_list[i][0]
    if task>AB_list[i][1]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
job = {}
for i in range(0, N):
    a, b = map(int, input().split())
    if b not in job:
        job[b] = []
    job[b].append(a)

# print(job)
job_sorted = sorted(job.items(), key=lambda x: x[0])
# print(job_sorted)

time = 0
for value in job_sorted:
    # for deadline, require in job_sorted.items():
    deadline = value[0]
    require = value[1]
    require.sort()
    for i in range(0, len(require)):
        time += require[i]
        # print('dead = {} : time = {}'.format(deadline, time))
        if time > deadline:
            print('No')
            exit()
print('Yes')

Submission status: Accepted

Solution code:
l=int(input())
a=[]
for i in range(l):
  m,n=(int(i) for i in input().split())
  a.append([n,m])
a.sort()
r="Yes"
s=0
for i in range(l):
  s=s+a[i][1]
  if s>a[i][0]:
    r="No"
    break
print(r)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: (x[1], -x[0]))
total = 0
for time, deadline in a:
    total += time
    if total > deadline:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
tasks = [[int(x) for x in input().split()] for _ in range(n)]
tasks_sorted = sorted(tasks, key=lambda x:x[1])
task = 0
ret = "Yes"
for i in range(len(tasks_sorted)):
    task += tasks_sorted[i][0]
    if task > tasks_sorted[i][1]:
        ret = "No"
        break
print(ret)

Submission status: Accepted

Solution code:
N=int(input())

tasks=[]
for _ in range(N):
  l=list(map(int,input().split()))
  tasks.append(l)
#print(tasks)

sorted_tasks=sorted(tasks,key = lambda x: (x[1], x[0]))
#print(sorted_tasks)

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

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()
by_due = sorted(tasks, key=lambda x: x[1])

worked = 0
for i in range(n):
    a, b = by_due[i]
    worked += a
    if worked > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
#d.py
n = int(input())
ab = [list(map(int,input().split())) for x in range(n)]
yes = True
time = 0
ab.sort(key=lambda x:x[1])
for x in ab:
    time += x[0]
    if time > x[1]:
        yes = False
        break
if yes:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter
from itertools import accumulate
import numpy as np
N = int(input())
work = []
for i in range(N):
  a, b = map(int, input().split())
  work.append([a, b])

work = sorted(work, key=itemgetter(1,0))
work = np.array(work)

ans = "Yes"
for idx, time in enumerate(list(accumulate(work[:,0]))):
  if time > work[idx,1]:
    ans = "No"
    break

print(ans)

Submission status: Accepted

Solution code:
num_task = int(input())

maps = [map(int, input().split(' ')) for _ in range(0, num_task)]
tasks = [(b, a) for a, b in maps]
tasks.sort()


current_time = 0

for deadline, time_needed in tasks:
    end_time = current_time + time_needed

    if end_time > deadline:
        print("No")
        break

    current_time = end_time

else:
    print("Yes")

Submission status: Accepted

Solution code:
import fractions

#inp = [int(i) for i in input().split()]
inp = int(input())

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

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

for dd in so:
    ti = dd[0] + ti
    if ti <= dd[1]:
        pass
    else:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

f = 0
sum = 0
for i in range(n):
    sum += li[i][1]
    if li[i][0] < sum:
        f = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
T = []
for i in range(N):
    a,b = map(int,input().split())
    T.append({'A':a, 'B':b})
T = sorted(T, key=lambda x: x['B'])

ans = 'Yes'
t = 0
for task in T:
    t += task['A']
    if t > task['B']:
        ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
N = list(map(int, input().split()))
N=N[0]
d={}
def dad(d,a,b):
    if a not in d:
        d[a]=[]
    d[a].append(b)

for x in range(N):
    A,B = list(map(int, input().split()))
    dad(d,B,A)

time=0
flag=0
for item in sorted(d.items()):
    for x in item[1]:
        time+=x
    if not time<=item[0]:
        flag=-1
        break
if flag==0:
    print("Yes")
else:
    print("No")

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

time=0
flag=0
for i,j in AB:
    time+=i
    if time>j:
        flag=1
        break
if flag==1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

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

ans = 0
for x in l:
    ans += x[0]
    if ans > x[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
AB = [tuple(map(int, input().strip().split(' '))) for i in range(N)]
AB.sort(key=lambda x: x[1])
count = 0
for a, b in AB:
    count += a
    if count > b:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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

time = 0

for a,b in AB:
    time += a
    if time <= b:
        pass
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
job = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    inputs = [int(s) for s in input().split()]
    job[i][0] = inputs[1]
    job[i][1] = inputs[0]

sortedJob = sorted(job)
times = 0
breaked = False
for i in range(n):
    times += sortedJob[i][1]
    if times > sortedJob[i][0]:
        breaked = True
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

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

sum_t = np.cumsum(ab_np[:, 0])


if any(ab_np[:,1]-sum_t < 0):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
# A = []
# B = []
A_B = []
for i in range(N):
    a, b = map(int, input().split())
    A_B.append([a,b])
C = sorted(A_B, key=lambda x:x[1])
sum = 0
import sys
for i in range(N):
    sum += C[i][0]
    if sum > C[i][1]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
X = {}
for a, b in L:
    if b not in X:
        X[b] = []
    X[b].append(a)
now = 0
for b, Y in sorted(X.items(), key=lambda x: x[0]):
    for a in Y:
        now += a
        if b < now:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ab = []
for i in range(N):
    a, b = map(int,input().split())
    ab.append([a,b])
ab.sort(key=lambda x:x[0])
ab.sort(key=lambda x:x[1])
cur = 0
ans = True
for i in range(N):
    cur += ab[i][0]
    if cur > ab[i][1]:
        ans = False
        break
print("Yes" if ans else "No")

Submission status: Accepted

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

time = 0
flag = True
for a, b in ab:
    time += a
    if time > b:
        print("No")
        flag = False
        break
        
if flag:
    print("Yes")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    C = zip(A, B)
    C = sorted(C, key=lambda x: x[1])
    A, B = zip(*C)
    t = 0
    ok = True
    for i in range(N):
        t += A[i]
        if t > B[i]:
            ok = False
            break

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
AB=[[0 for i in range(2)] for j in range(N)]
for i in range(N):
    AB[i][0],AB[i][1]=map(int, input().split())
AB=sorted(AB, key=lambda x: x[1])
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())
AB=[]


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

for i in range(N-1):
    AB[i+1][1]+=AB[i][1]

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
data = sorted(data,key=lambda x:x[1])
stack_labor = 0
flag = True
for i in data:
    stack_labor += i[0]
    if stack_labor > i[1]:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
AB = sorted([list(map(int,input().split())) for i in range(n)],key=lambda x:x[1])
# print(AB)
tmp=0
for a,b in AB:
	if tmp+a<=b:
		pass
	else:
		print("No")
		exit()
	tmp+=a
print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
ab = [input().split() for i in range(n)]
ab = [[int(ab[i][0]),int(ab[i][1])] for i in range(n)]
ab.sort(key=itemgetter(1))
flg = 0
t = 0
for i in range(n):
  t += ab[i][0]
  if t > ab[i][1]:
    flg = 1
    break
if flg == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n = int(input())
task = [[int(i) for i in input().split()] for _ in range(n)]
task.sort(key=lambda x:x[1])
t = 0
for i in task:
    t += i[0]
    if t > i[1]:
        exit(print('No'))
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

dic = {}

for _ in range(N):
    A,B = map(int,input().split())
    if B in dic:
        dic[B] += A
    else:
        dic[B] = A

cum = 0    
flag = True
dic_sort = sorted(dic.items(), key=lambda x:x[0])

for bb,aa in dic_sort:
    cum += aa
    if bb < cum:
        flag = False
        break

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

Submission status: Accepted

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

ans = "Yes"
c = 0
for i, v in enumerate(ba):
    b, a = v
    c += a
    if c > b:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

BA = []

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

BA.sort()

a = 0

flg = False
for ba in BA:
    b = ba[0]
    a += ba[1]
    if b < a:
        flg = True
        break

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
tasks = np.empty(shape=(N,2), dtype=np.int64)
for i in range(N):
    a, b = map(int, input().split())
    tasks[i,0] = a
    tasks[i,1] = b
tasks = tasks[np.argsort(tasks[:,1])]

progress = 0
deadline = False
for i in range(N):
    progress += tasks[i,0]
    if progress > tasks[i,1]:
        deadline = True
        break

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

Submission status: Accepted

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

W=sorted(W,key=lambda x:x[1])
#print(W)
#print('==================')
total = 0
can = True
for (need, limit) in W:
#    print(str(total)+' '+str(need)+' '+str(limit))
    total += need
    if total > limit:
        can = False
        break
if can:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

flag = True
now = 0
li = sorted(li)

for a, b, c in li:
    now += b
    if now > c:
        print("No")
        flag = False
        break
        
if flag:
    print("Yes")

Submission status: Accepted

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

sa = sorted(a, key=lambda x:x[1])
suma = 0
flag = True
for i in range(N):
  suma += sa[i][0]
  if suma > sa[i][1]:
    flag = False
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

m = 0
B = set()
for i in range(N):
    a,b = map(int,input().split())
    dic[b] += a
    B.add(b)
    if m < b: m = b
B = sorted(B)

flag = True
sub = 0
for b in B:
    sub += dic[b]
    if b-sub < 0:
        flag = False
        break

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

Submission status: Accepted

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

AB = sorted(AB, key=lambda x: x[1])
sa = 0
sb = 0
flag = True
for a, b in AB:
    sa += a
    sb = b
    if sa > sb:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

N = int(input())

task_list = [[0, 0]] * N

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

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

goodjob = True
time = 0
for (a_i, b_i) in sorted_list:
    time += a_i
    if time > b_i:
        goodjob = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for i in range(N):
    A, B = map(int, input().split())
    if d.get(B) is None:
        d[B] = [A]
    else:
        d[B].append(A)

ans = 1
works = 0

for k in sorted(d):
    if works + sum(d[k]) > k:
        ans = 0
        break
    works += sum(d[k])
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())

w = [[0 for i in range(2)]for i in range(n)]

ans = "Yes"
total = 0
for i in range(n):
    a,b = map(int, input().split())
    w[i][0] = b
    w[i][1] = -a

w.sort()

for i in range(n):
    total += -1*w[i][1]
    #print(total, w[i][0])
    if total > w[i][0]:
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

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

def solve(N: int, A: "List[int]", B: "List[int]"):
    ab = [[A[i],B[i]] for i in range(N)]

    t = 0
    ab = sorted(ab, key=lambda x:x[1])
    for i in range(N):
        t += ab[i][0]
        if(t > ab[i][1]):
            print(NO)
            exit()
        
    print(YES)
    return


# 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
    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))
    solve(N, A, B)

if __name__ == '__main__':
    main()