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: Wrong Answer

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

def my_sort(L, C, p, q):
    if p < q:
        mid = (p + q) // 2
        my_sort(L, C, p, mid)
        my_sort(L, C, mid + 1, q)
        i = p
        j = mid + 1
        k = p
        tmp = 0
        while k <= q:
            if i > mid:
                tmp = L[j]
                j += 1
            elif j > q:
                tmp = L[i]
                i += 1
            else:
                if L[i][1] <= L[j][1]:
                    tmp = L[i]
                    i += 1
                else:
                    tmp = L[j]
                    j += 1
            C[k] = tmp
            k += 1
        for i in range(p, q + 1):
            L[i] = C[i]

n = int(input())
task = []
time_total = [0 for i in range(n)]
for i in range(n):
    task.append([int(i) for i in input().split()])
task_sorted = [[0, 0] for i in range(n)]
my_sort(task, task_sorted, 0, n - 1)
time_total[0] = task_sorted[0][0]
for i in range(n - 1):
    time_total[i + 1] = time_total[i] + task_sorted[i + 1][0]
while i < n:
    if time_total[i] > task_sorted[i][1]:
        print("No")
        sys.exit()
    i += 1
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ba = [[b, a] for a, b in ab]
ba.sort(reverse=True)

f = True
for i in range(n-1):
    ba[i+1][0] = min(ba[i+1][0], ba[i][0]-ba[i][1])
    if ba[i+1][0]-ba[i+1][1]<0:
        f = False
if f:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ba = [[b, a] for a, b in ab]
ba.sort(reverse=True)

f = True
for i in range(n-1):
    ba[i+1][0] = ba[i][0]-ba[i][1]
    if ba[i+1][0]-ba[i+1][1]<0:
        f = False
if f:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

q = 0
w = 0
flg = 0
for j in a:
  q += j[0]
  w += j[1]
  if q > w :
    flg = 1
    break

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

Submission status: Wrong Answer

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

deadline = [i[1] for i in work]
time = [i[0] for i in work]

indices = [i for i in range(n)]
sorted_indices = sorted(indices, key=lambda i: deadline[i])

sorted_deadline = [deadline[i] for i in sorted_indices]

dic = {}

for i, j in zip(sorted_indices,sorted_deadline):
    if not j in dic:
        dic[j] = time[i]
    
    else:
        dic[j] += time[i]

left_time = 0

able = True
for k,v in dic.items():
    left_time += (k-v)
    if left_time < 0:
        able = False

if able:
    print('Yes')

else:
    print('No')

Submission status: Wrong Answer

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

for i in range(N):
    ab[i].append(ab[i][1] - ab[i][0])

from operator import itemgetter
ab.sort(key=itemgetter(2))

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

Submission status: Wrong Answer

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

for i in range(N):
    ab[i].append(ab[i][1] - ab[i][0])

from operator import itemgetter
ab.sort(key=itemgetter(2))

cnt = 0
max_ = 0
for i in range(N):
    cnt += ab[i][0]
    max_ = max(max_, ab[i][1])
if cnt > max_:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

for i in range(N):
    ab[i].append(ab[i][1] - ab[i][0])

from operator import itemgetter
ab.sort(key=itemgetter(2))

cnt = 0
max_ = 0
for i in range(N):
    cnt += ab[i][0]
    max_ = max(max_, ab[i][1])
if cnt > ab[N - 1][1]:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

for i in range(N):
    ab[i].append(ab[i][1] - ab[i][0])

from operator import itemgetter
ab.sort(key=itemgetter(2))

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

Submission status: Wrong Answer

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

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

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



''''
task=[]
for ab in AB:
    for _ in range(ab[0]):
        task.append(ab[1])
#print(AB)
#print(task)

for i in range(len(task)):
    if i+1>task[i]:
        print('No')
        break
else:
    print('Yes')
'''

Submission status: Wrong Answer

Solution code:
N=int(input())

l=[]

for i in range(N):
  x,y=[int(x) for x in input().rstrip().split()]
  l.append([x,y])

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

now=0
ans=0
for i in range(N):
  now+=l[i][0]
if now<=l[N-1][1]:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
H = []
for _ in range(N):
    A, B = map(int,input().split())
    H.append((B - A, A))
H.sort()
t = 0
for i in range(N):
    S, A = H[i]
    if S < t:
        print("No")
        break
    t += A
    if len(H) == 0:
        print("Yes")

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
N = int(input())
H = []
for _ in range(N):
    A, B = map(int,input().split())
    heappush(H, (B - A, A))
t = 0
for _ in range(N):
    S, A = heappop(H)
    if S < t:
        print("No")
        break
    t += A
    if len(H) == 0:
        print("Yes")

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
N = int(input())
H = []
for _ in range(N):
    A, B = map(int,input().split())
    heappush(H, (B - A, A))
t = 0
for _ in range(N):
    S, A = heappop(H)
    if S > t:
        print("No")
        break
    t += A
    if len(H) == 0:
        print("Yes")

Submission status: Wrong Answer

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

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

lefttime = ab[0][1]
for a, b in ab:
    lefttime -= a

    if lefttime < 0:
        print("No")
        exit()

    lefttime = min(lefttime, b)

print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [list(map(int,input().split())) for _ in range(n)]
AB.sort(key=lambda x: x[1], reverse=True)
# print(AB)
free = 0
now = 0
ok = True
for necessary, deadline in AB:
    if necessary <= free:
        free -= necessary
        continue
    if now + necessary > deadline:
        ok = False
        break
    free = deadline - necessary - now
    now = deadline

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

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

job.sort(key = itemgetter(1))

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

Submission status: Wrong Answer

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

for i in range(N):
    temp = job[i]
    for j in range(i-1, -1, -1):
        if job[j][1] < temp[1]:
            job[j+1] = temp
            break
        job[j+1] = job[j]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(answer)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB={}
answer="Yes"
for i in range(N):
    a,b=map(int,input().split())
    if b not in AB.keys():
        AB[b]=a
    else:
        AB[b]+=a
        if AB[b]>b:
            answer="No"

print(answer)

Submission status: Wrong Answer

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

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

import sys
work = 0

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
for i in range (N):
	A.append(list(map(int,input().split())))
for i in range (N):
	B.append(A[i][1])
C=sorted(A,key=lambda A: A[1])
tmp=0
count=0
for i in range (N):
  tmp+=C[i][0]
  if tmp<=C[i][1]:
    count+=1
  else:
    print("No")
if count==N:
  print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
x=dict()
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
t=0
bm=max(B)
sa=sum(A)
if sa<=bm:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

curtime = 0
for i in task:
  curtime += i[0]
  if curtime > i[1]:
    print("No")
    break
if curtime <= task[-1][1]:
  print("Yes")

Submission status: Wrong Answer

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

curtime = 0
for i in task:
  curtime += i[0]
  if curtime > i[1]:
    print("No")
    break
  print(curtime)
if curtime <= task[-1][1]:
  print("Yes")

Submission status: Wrong Answer

Solution code:

N = int(input())

d_list = []

P = [map(int, input().split()) for i in range(N)]
for A, B in P:
    d_list.append({"cost": A, "limit": B, "remain": B - A})

sorted_dict_list = sorted(d_list, key=lambda x:x['limit'])

total_cost = 0
for d in sorted_dict_list:
    if total_cost + d["cost"] > d["limit"]:
        total_cost = -1
        break
    total_cost += d["cost"]

if total_cost == -1:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b])
    
ab.sort(key=lambda x:x[1])

limit = 0
for i in range(n):
    limit += ab[i][0]
    if limit < ab[i][1]:
        print("No")
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

jobs = []
for _ in range(int(input())):
    a, b = [int(i) for i in input().split()]
    if b - a < 0:
        print("No")
        sys.exit()
    jobs.append((a, b, b - a + 1))

jobs.sort(key=lambda j: j[1])
curr_jour = 0

for j in jobs:
    if curr_jour > j[2]:
        print("No")
        sys.exit()
    curr_jour += j[0]

print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

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

print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

days = ab[0][0]

i = 1
ans = 'Yes'
while i < n:
    days += ab[i][0]
    print(days)
    if days > ab[i][1]:
        ans = 'No'
        break
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

limit = ab[0][1] - ab[0][0]

i = 1
ans = 'Yes'
while i < n:
    limit -= ab[i][0]
    if limit < 0:
        ans = 'No'
        break
    i += 1
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

time = None
for deadline, task_time in deadlines:
    if time is None:
        time = deadline - task_time
        continue

    if time - task_time >= 0:
        time -= task_time
    else:
        time = None
        break
print('Yes' if time is not None else 'No')

Submission status: Wrong Answer

Solution code:
N = int(input())
list_A=[]
list_B=[]
list_AB=[]
for i in range(N):
	A, B = map(int,input().split())
	list_A.append(A)
	list_B.append(B)
	list_AB.append([list_A[i],list_B[i]])
sort_AB =sorted(list_AB, key=lambda x: x[1])
u=[]
def _judge_(k):
	for j in range(N-1):
		if k[j][0]>k[j][1]:
			return print("No")
		else:
			u.append(k[j][0])
			if sum(u)+k[j+1][0]>k[j+1][1]:
				return print("No")
	return print("Yes")

_judge_(sort_AB)

Submission status: Wrong Answer

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

am = 0
bm = 0
bdict = {}

for i in range(n):
    am += a[i]
    bm = max(bm, b[i])
    if b[i] in bdict.keys():
        bdict[b[i]] += a[i]
        if b[i] < bdict[b[i]]:
            print("No")
            exit()
    else:
        bdict[b[i]] = a[i]

    if a[i] > b[i]:
        print("No")
        exit()
    
if am <= bm:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

am = 0
bm = 0
for i in range(n):
    am += a[i]
    bm = max(bm, b[i])
    if a[i] > b[i]:
        print("No")
        exit()
    
if am <= bm:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

am = 0
bm = 0
for i in range(n):
    am += a[i]
    bm = max(bm, b[i])
    
if am <= bm:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
abs = [tuple(map(int, input().split())) for _ in range(n)]

pq = []

for ab in abs:
  a,b = ab[0],ab[1]
  heapq.heappush(pq, tuple([b,a]))
  
dl = 0
tc = 0

ans = "Yes"

for i in range(n):
  ba = pq.pop()
  dl = ba[0]
  tc += ba[1]
  if dl < tc:
    ans = "No"
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
abs = [tuple(map(int, input().split())) for _ in range(n)]

pq = []

for ab in abs:
  a,b = ab[0],ab[1]
  heapq.heappush(pq, tuple([b,a]))
  
dl = 0
tc = 0

ans = "Yes"

for i in range(n):
  ba = pq.pop()
  dl += ba[0]
  tc += ba[1]
  if dl < tc:
    ans = "No"
    break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if SUM_<=AB[-1][-1]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

J.sort(key=lambda x: x[1], reverse=True)

t = J[0][1]

for a, b in J:
    if t >= 0:
        t -= a
    else:
        res = 'No'
        break
else:
    res = 'Yes'

print(res)

Submission status: Wrong Answer

Solution code:
#m = imt(imput())
#L = list(map(imt, imput().split()))
import math
import sys

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


def aa(N,AB):
    AB.sort(key=lambda x: x[1])
    for i in range(N-1):
        clk += AB[i][0]
        if clk >= AB[i][1]:
            flg = False
            break
    if flg:
        return "Yes"
    else:
        return "No"

Submission status: Wrong Answer

Solution code:
N = int(input())

AB = []
for i in range(N):
  AB.append(list(map(int, input().split()))[::-1])

AB.sort()
ans = 'Yes'
for i in range(1, N):
  AB[i][1] += AB[i-1][1]
  if AB[i][1] > AB[i][0]:
    ans = 'No'
    break

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	# b = int(input())
	# a = list(map(int,input().split()))
	l = [list(map(int, input().split())) for _ in range(n)]
	# print(a)
	
	# l_s = sorted(l, reverse=True, key=lambda x: x[1])
	l_s = sorted(l)
	# print(l_s)
	count = []
	for i in l_s:
		count.append(i[1])

	c_max = max(count)
	sime = 0
	for i in l_s:
		 sime += i[0]
		# print("c_max is {}".format(c_max))
	if sime <= c_max:
		print("Yes")
	else:
		print("No")






if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	n = int(input())
	# b = int(input())
	# a = list(map(int,input().split()))
	l = [list(map(int, input().split())) for _ in range(n)]
	# print(a)
	
	l_s = sorted(l, reverse=True, key=lambda x: x[1])
	# print(l_s)
	count = []
	for i in l_s:
		count.append(i[1])

	c_max = max(count)
	
	for i in l_s:
		c_max -= i[0]
		# print("c_max is {}".format(c_max))
	if c_max >= 0:
		print("Yes")
	else:
		print("No")






if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

C = zip(B, A)
C = sorted(C)


A, B = zip(*C)
A = list(A)
B = list(B)



t = 0
o = 0
for i, j in zip(B, A):
    if t>j:
        print("No")
        o = 1
        break
    else:
        t += i

if o == 0 and t < j:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def calculate(list):
    current = 0
    for item in list:
        current += item[0]
        if current > item[1]:
            return False

    return True

N = int(input())

arr = []
for i in range(N):
    arr.append([int(s) for s in input().split(" ")])

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

result = calculate(arr2)

print(result)

Submission status: Wrong Answer

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

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

for i in range(n):
    time -= ab[i][0]
else:
    if time >= 0:
        ans = "Yes"
    else:
        ans = "No"

print(ans)

Submission status: Wrong Answer

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

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

for i in range(n):
    time -= ab[i][0]
else:
    if time >= 0:
        ans = "yes"
    else:
        ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

N = int(input())

A = []
B = []
for i in range(N):
    a1, b1 = map(int, input().split())
    A.append(a1)
    B.append(b1)
    
b = np.argsort(B)

for i in range(N):
    A[i] = A[b[i]]
    B[i] = B[b[i]]

wt = 0
for i in range(N):
    l = B[i]
    wt += A[i]
    if wt > l:
        print("No")
        sys.exit()
        
print("Yes")

Submission status: Wrong Answer

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

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

s = 0
for A, B in AB:
    s += A
    if s > B:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
work = [[int(j) for j in input().split(" ")] for i in range(n)]
work = sorted(work,key = lambda x:(x[1],x[0]))

time = 0
for work_time, limit_time in work:
    time += work_time
    print(time,limit_time)
    if time > limit_time:
        print("No")
        break

else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import bisect
import copy

n = int(input())
A = []
B = []
task = []
now = 0
for _ in range(n):
    a, b = map(int, input().split())
    task.append([a, b])
    A.append(a)
    B.append(b)

if sum(A) >= max(B):
    print('No')
    exit()

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

for i, t1 in enumerate(copy.deepcopy(task[:-1])):
    if t1 in r:
        continue
    for t2 in copy.deepcopy(task[i+1:]):
        if now + t2[0] <= t1[1] - t1[0]:
            now += t2[0]
            r.append(t2)
        else:
            break
    if now + t1[0] > t1[1]:
        print('No')
        exit()
    else:
        now += t1[0]
print('Yes')

Submission status: Wrong Answer

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

ab=sorted(ab, key=lambda x: x[1])
a_sum=0
for i in range(n):
    a_sum+=ab[i][0]
print('Yes' if a_sum<ab[n-1][1] else 'No')

Submission status: Wrong Answer

Solution code:
n=int(input())

ab=[list(map(int,input().split())) for _ in range(n)]
ab=sorted(ab, key=lambda x: x[1])
a_sum=0
for i in range(n):
    a_sum+=ab[i][0]
print('Yes' if a_sum<=ab[n-1][1] else 'No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[1]-x[0])
cur = 0
aki = 0
for a, b in AB:
    if cur <= b-a:
        aki += (b-a)-cur
        cur += (b-a)-cur+a
    else:
        if aki >= a:
            aki -= a
        else:
            a -= aki
            if cur + a > b:
                print('No')
                exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
if sum([a for a, b in AB]) <= max([b for a, b in AB]):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
task = []
res_a = 0
res_b = 0
for _ in range(n):
  a,b = list(map(int, input().split()))
  res_a += a
  res_b += b
  if(res_a > b):
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    tasks = []
    for i in range(n):
        tasks.append(list(map(int,input().split(" "))))
    print(solve(tasks))

def solve(tasks):
    t = 0
    tasks.sort(key=lambda i:i[1])
    for task in tasks:
        t += task[0]
        if t >= task[1]:
            return "No"
    return "Yes"




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
#N=5
#A,B = [2,1,1,4,3],[4,9,8,9,12]
A,B = [],[]
for i in range(N):
    a,b = input().split()
    A.append(int(a))
    B.append(int(b))


import numpy as np
C = np.array([A,B])

C = C[:,C[1,:].argsort()]
A,B = C[0],C[1]
print(C)
i=0
while(i<N):
    n=0
    #ind = i+n
    while((i+n<N) and (B[i]==B[i+n])):
        n += 1
    if(n>1):
        #print(n,i,A[i:i+n] )
        #pdb.set_trace()
        A[i:i+n] = A[i:i+n][::-1]
    i+=n
"""
print(A,B)
sum_ = 0
y=[]
b = []
for i in range(N):
    sum_ += A[i]
    y.append(sum_)
    b.append(B[i])
plt.plot(y)
plt.plot(b)
plt.show()
plt.close()"""
time = 0
hantei = 0
for i in range(N):
    time += A[i]
    if(time>B[i]):
        hantei = 1
        break
        
print("Yes") if hantei==0 else print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
W=[]
for i in range(N):
    A, B = list(map(int, input().split()))
    W.append([A, B])
W.sort(key=lambda x:x[1])
Sum = 0
f = 0
for i in range(N):
    Sum = Sum+W[i][0]
    if Sum > W[i][1]:
        print("No")
        f = f+1
if f != 1:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
C = [] #最遅入り時間
for i in range(N):
    a, b = map(int, input().split())
    C.append((a, b, i))
C.sort(key=lambda x:x[1])

t = 0
ans = 'Yes'
for i in range(N):
    if C[i][1] - C[i][0] < t:
        ans = 'No'
        print(i)
        break
    t += C[i][0]

print(ans)

Submission status: Wrong Answer

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

t=0
flag=True
for _ in range(n):
  i=b.index(min(b))
  j=sorted(a)[i]
  k=sorted(b)[i]
  if j>k-t:
    print('No')
    flag=False
    break
  else:
    t += j
if flag:
  print('Yes')

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
ab = sorted(ab,key = itemgetter(1))
flag = ab[0][1] - ab[0][0]
flag_2 = 0
for j in range(1,n):
  flag += (ab[j][1]-ab[j-1][1])-ab[j][0]
  if flag < 0:
    print("No")
    flag_2 = 1
    break
if flag_2 == 0:
  print("Yes")

Submission status: Wrong Answer

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

for i in range(N):
    M,L=(int(j) for j in input().split())
    A.append(M)
    B.append(L)


for i in range(N):
    index=B.index(min(B))
    if (time+A[index])>B[index]:
        print("No")
        break;
    elif time+sum(A)>max(B):
        print("No")
        break;
    elif time+sum(A)>=B[index]:
        print("Yes")
        break;
    else:
        time=time+A[index]
        del A[index]
        del B[index]
print(A)
if not A:
    print("Yes")

Submission status: Wrong Answer

Solution code:
def bSort(a,b):
    for i in range(len(a)):
        for j in range(len(b)-1,i,-1):
            if b[j] < b[j-1]:
                       b[j],b[j-1] = b[j-1],a[j]
                       a[j],a[j-1] = a[j-1],b[j]
    return a,b
n = int(input())
a = []
b = []
for i in range(n):
    l,m =list(map(int ,input().strip().split()))
    a.append(l)
    b.append(m)
bSort(a,b)

sum = a[0]
for i in range(n):
    if sum <= b[i]:
        if i == n-1:
            print("Yes")
        sum += a[i]
        continue
    else:
        print("No")
        break

Submission status: Wrong Answer

Solution code:
def bSort(a,b):
    for i in range(len(a)):
        for j in range(len(b)-1,i,-1):
            if b[j] < b[j-1]:
                       b[j],b[j-1] = b[j-1],a[j]
                       a[j],a[j-1] = a[j-1],b[j]
    return a,b
n = int(input())
a = []
b = []
for i in range(n):
    l,m =list(map(int ,input().strip().split()))
    a.append(l)
    b.append(m)
#bSort(a,b)

sum = a[0]
for i in range(n):
    if sum <= b[i]:
        if i == n-1:
            print("Yes")
        sum += a[i]
        continue
    else:
        print("No")
        break

Submission status: Wrong Answer

Solution code:
N=int(input())
t1=0
t2=0

c=[]
d=[]
count=0
time=0
flag='Yes'

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


Time=c[N-1][1]

while(True):
    d=[]
    for i in range(N-1-count,-1,-1):
        if c[i][1]>=Time:
            d.append(c[i])
        else:
            break
    

    if len(d)==0:
        break
    
    d.sort()
    if Time>=d[len(d)-1][0]:
        Time-=d[len(d)-1][0]
    else:
        flag='No'
        break
    c.remove(d[len(d)-1])
    count+=1

print(flag)