qyliang/CodeNanoFix huggingface dataset:
Buggy 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 range(n):
  q += j[0]
  w += j[1]
  if q > w :
    flg = 1
    break

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

Fixed 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')
Buggy 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("Bad")

Fixed 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")
Buggy code:
import sys

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

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


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


time = 0

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


Fixed code:
import sys

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

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


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

time = 0

for i in range(N):
    time += sorted_tasks[i][0]
    if time > sorted_tasks[i][1]:
        print("No")
        sys.exit()
        
print("Yes")
Buggy 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")

Fixed 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")
Buggy code:
import itertools

def input_ints():
    return list(map(int, input().split()))

def output_list(v):
    print(' '.join(str(x) for x in v))

def main():
    n = int(input())
    p = []
    for i in range(n):
        a, b = input_ints()
        p.append((b - a, b))
    p.sort()
    t = 0
    for i in range(n):
        if t > p[i][0]:
            print('NO')
            return
        t += p[i][1] - p[i][0]
    print('YES')


if __name__ == '__main__':
    main()


Fixed code:
import itertools

def input_ints():
    return list(map(int, input().split()))

def output_list(v):
    print(' '.join(str(x) for x in v))

def main():
    n = int(input())
    p = []
    for i in range(n):
        a, b = input_ints()
        p.append((b, a))
    p.sort()
    t = 0
    for i in range(n):
        if t > p[i][0] - p[i][1]:
            print('No')
            return
        t += p[i][1]
    print('Yes')


if __name__ == '__main__':
    main()
Buggy 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=0
tmp=0
for i in range(n):
    tmp=l[i][1]
    deadline+=l[i][0]
    if tmp<deadline
        print("No")
        exit()
print("Yes")

Fixed 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=0
tmp=0
for i in range(n):
    tmp=l[i][1]
    deadline+=l[i][0]
    if tmp<deadline:
        print("No")
        exit()
print("Yes")
Buggy code:
import sys
input = sys.stdin.readline


def main():
    AB = []
    n = int(input())
    for i in range(n):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB = sorted(AB, key=lambda x: (x[1], -x[0]))
    time = 0
    for span, dead in zip(AB):
        time += span
        if time > dead:
            print('No')
            return
    print('Yes')
    return


if __name__ == "__main__":
    main()


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


def main():
    AB = []
    n = int(input())
    for i in range(n):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB = sorted(AB, key=lambda x: (x[1], -x[0]))
    time = 0
    for span, dead in AB:
        time += span
        if time > dead:
            print('No')
            return
    print('Yes')
    return


if __name__ == "__main__":
    main()
Buggy code:
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    T = [ tuple( map( int, input().split())) for _ in range(N)]
    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()


Fixed 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()
Buggy 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]

	print(limit, work)

	if work > limit:

		fail = 1

		break


if fail == 1:

	print("No")

else:

	print("Yes")

Fixed 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")
Buggy code:
import sys
n = int(input())
li = sorted(map(lambda x: list(map(int, x.split()[::-1])), sys.stdin.readlines()))
print(li)
sum = 0
flag = "Yes"
for x, y in li:
  sum += y
  if x < sum:
    flag = "No"
    break
    
print(flag)
    

Fixed code:
import sys
n = int(input())
li = sorted(map(lambda x: list(map(int, x.split()[::-1])), sys.stdin.readlines()))
sum = 0
flag = "Yes"
for x, y in li:
  sum += y
  if x < sum:
    flag = "No"
    break
    
print(flag)
Buggy code:
from operator import itemgetter
n=int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
c=sorted(ab, key=itemgetter(1), reverse=False)
f=True
t=0
for i in range(n):
    t = t + c[i][0]
    print(t)
    f=f and t<c[i][1]
if f:
    print("Yes")
else:
    print("No")

Fixed code:
from operator import itemgetter
n=int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
c=sorted(ab, key=itemgetter(1), reverse=False)
f=True
t=0
for i in range(n):
    t = t + c[i][0]
    f=f and t<=c[i][1]
if f:
    print("Yes")
else:
    print("No")
Buggy code:
N = int(input())
ab_list = []
for _ in range(N):
    ab_list.append([int(x) for x in input().split()])
    
ab_list = sorted(ab_list, key=lambda x: x[-1])

sum_work = 0
res = 'Yes'
for a, b in ab_list:
    sum_work += a
    if sum_work >= b:
        res = 'No'
        break
print(res)

Fixed code:
N = int(input())
ab_list = []
for _ in range(N):
    ab_list.append([int(x) for x in input().split()])
    
ab_list = sorted(ab_list, key=lambda x: x[-1])

sum_work = 0
res = 'Yes'
for a, b in ab_list:
    sum_work += a
    if sum_work > b:
        res = 'No'
        break
print(res)
Buggy code:
N = int(input())
count = 0
D = 0
task = [list(map(int, input().split())) for _ in range(N)]
task = sorted(task, key = lambda x:x[1])
print(task)
for i in range(N):
  count += task[i][0]
  if count > task[i][1]:
    print("No")
    D = 1
    break
if D== 0:
  print("Yes")

Fixed code:

N = int(input())
count = 0
D = 0
task = [list(map(int, input().split())) for _ in range(N)]
task = sorted(task, key = lambda x:x[1])
for i in range(N):
  count += task[i][0]
  if count > task[i][1]:
    print("No")
    D = 1
    break
if D== 0:
  print("Yes")
Buggy code:
N = int(input())

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

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

s_w_l = list(map(lambda x: x[1], s_w))
s_w_c = list(map(lambda x: x[0], s_w))

import numpy as np
if all(np.cumsum(np.array(s_w_c)) <= np.cumsum(np.array(s_w_l))):
    print('Yes')
else:
    print('No')

Fixed code:
N = int(input())

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

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

s_w_l = list(map(lambda x: x[1], s_w))
s_w_c = list(map(lambda x: x[0], s_w))

import numpy as np
if all(np.cumsum(np.array(s_w_c)) <= np.array(s_w_l)):
    print('Yes')
else:
    print('No')
Buggy 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]))):
  print(idx, time)
  if time > work[idx,1]:
    ans = "No"
    break

print(ans)

Fixed 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)
Buggy code:
N = int(input())

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

A.sort(lambda x: x[1], x[0])

gokei = 0
for i in A:
    gokei += i[0]
    if gokei > i[1]:
        print("No")
else:
    print("Yes")

Fixed code:
N = int(input())

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

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

gokei = 0
for i in A:
    gokei += i[0]
    if gokei > i[1]:
        print("No")
        break
else:
    print("Yes")
Buggy code:
N = int(input())
L = []
for i in range(N):
    l = list(map(int, input().split()))
    L.append(l)

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

cnt = 0
flag = True
for i in range(N):
    #cnt += L[0][i]
    print(L[i][0])
    cnt += L[i][0]
    #if cnt <= L[i][1]:
    if cnt > L[i][1]:
        flag = False
        break

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


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

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

cnt = 0
flag = True
for i in range(N):
    #cnt += L[0][i]
#    print(L[i][0])
    cnt += L[i][0]
    #if cnt <= L[i][1]:
    if cnt > L[i][1]:
        flag = False
        break

if flag == True:
    print("Yes")
else:
    print("No")
Buggy code:
for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])

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

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

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

 task.sort(key= lambda x:x[1])
 time = 0
 for a,b in task:
     time += a
     if time > b:
         print("No")
         break
    else:
        print("Yes")

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

task.sort(key= lambda x: x[1])
time = 0
for i in range(n):
    time += task[i][0]
    if time > task[i][1]:
        print("No")
        break
else:
    print("Yes")
Buggy code:
from operator import itemgetter
N = int(input())
AB = []
for _ in range(N):
    A, B = map(int, input().split())
    AB.append([B-A, A, B])
AB.sort(key=itemgetter(0))
cnt = 0
for _, a, b in AB:
    cnt += a
    if cnt > b:
        print("No")
        exit()
print("Yes")

Fixed code:
from operator import itemgetter
N = int(input())
AB = []
for _ in range(N):
    A, B = map(int, input().split())
    AB.append([A, B])
AB.sort(key=itemgetter(1))
cnt = 0
for a, b in AB:
    cnt += a
    if cnt > b:
        print("No")
        exit()
print("Yes")
Buggy code:
from collections import deque
N = int(input())
A = deque()
for _ in range(N):
    a,b = list(map(int,input().split()))
    A.append([b,a])
A = list(A)
A.sort()
print(A)
time = 0
for i in A:
    time += i[1]
    if time > i[0]:
        print('No')
        exit()
print('Yes')

Fixed code:
from collections import deque
N = int(input())
A = deque()
for _ in range(N):
    a,b = list(map(int,input().split()))
    A.append([b,a])
A = list(A)
A.sort()
time = 0
for i in A:
    time += i[1]
    if time > i[0]:
        print('No')
        exit()
print('Yes')
Buggy code:
import numpy as np
import sys

if __name__ == '__main__':
    n = int(input())
    works = np.array([[int(i) for i in input().split()] for i in range(n)])
    col_num = 1
    sorted_works = works[np.argsort(works[:, col_num])]
    print(sorted_works)
    time = 0
    for i in range(n):
        time += sorted_works[i][0]
        if time > sorted_works[i][1]:
            print("No")
            sys.exit()

        else:
            None

    print("Yes")


Fixed code:
import numpy as np
import sys

if __name__ == '__main__':
    n = int(input())
    works = np.array([[int(i) for i in input().split()] for i in range(n)])
    col_num = 1
    sorted_works = works[np.argsort(works[:, col_num])]
    time = 0
    for i in range(n):
        time += sorted_works[i][0]
        if time > sorted_works[i][1]:
            print("No")
            sys.exit()

        else:
            None

    print("Yes")
Buggy code:
n = int(input())

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


sum_a = 0
ch_over = 1

for i in range(n):
    sum_a += task_lis[i][1]
    if task_lis[i][0] < sum_a:
        ch_over = 0
        break

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


Fixed code:
n = int(input())
task_lis = sorted([[int(i) for i in input().split()] for _ in range(n)], key = lambda x:x[1])


sum_a = 0
ch_over = 1

for i in range(n):
    sum_a += task_lis[i][0]
    if task_lis[i][1] < sum_a:
        ch_over = 0
        break

if ch_over == 0:
    print("No")
else:
    print("Yes")
Buggy 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')

Fixed 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')
        break
else:
    print('Yes')
Buggy 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 a > b:
        print("No")
        break
print("Yes")

Fixed 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")
Buggy code:

def code_for_D(test=None):

    N = int(input())

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

    time_now = 0
    time_by = 0
    answer = 'Yes'

    for i in range(N):
        time_now += works[0]
        time_by = works[1]
        
        if time_now > time_by:
            answer = 'No'
        
    print(answer)


def main():
    code_for_C()


if __name__ == '__main__':
    main()


Fixed code:
def code_for_D(test=None):

    N = int(input())

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

    time_now = 0
    answer = 'Yes'

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

        if time_now > time_by:
            answer = 'No'

    print(answer)


def main():
    code_for_D()


if __name__ == '__main__':
    main()
Buggy code:
from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = sorted(tuple(map(int, reversed(input().split())) for _ in range(n)))
c, d = (map(itemgetter(i), a) for i in (0, 1))
print('YNeos'[any(x < y for x, y in zip(c, accumulate(d)))::2])

Fixed code:
from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = sorted((tuple(map(int, input().split())) for _ in range(n)),
           key=itemgetter(1))
c, d = (map(itemgetter(i), a) for i in (0, 1))
print('YNeos'[any(x > y for x, y in zip(accumulate(c), d))::2])
Buggy code:
from operator import itemgetter
from itertools import accumulate

n = int(input())
a = sorted((tuple(map(int, input().split())) for _ in range(n)),
           key=itemgetter(1))
c, d = zip(*a)
print('YNEOS'[any(x > y for x, y in zip(accumulate(c), d))::2])


Fixed code:
from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = sorted((tuple(map(int, input().split())) for _ in range(n)),
           key=itemgetter(1))
c, d = zip(*a)
print('YNeos'[any(x > y for x, y in zip(accumulate(c), d))::2])
Buggy code:
from itertools import accumulate

n = int(input())
a = sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))
c, d = zip(*a)
print('YNEOS'[any(x < y for x, y in zip(c, accumulate(d)))::2])


Fixed code:
from itertools import accumulate

n = int(input())
a = sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))
c, d = zip(*a)
print('YNeos'[any(x < y for x, y in zip(c, accumulate(d)))::2])
Buggy code:
n = int(input())
a_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_list.append([a,b])
    
new_list = sorted(a_list, key = lambda x: x[1])

def detect(alist):
  time = 0
  for item in a_list:
    if time >= item[1]:
      return "No"
    else:
      time += item[0]
  return "Yes"

print(detect(new_list))


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

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

def detect(alist):
  time = 0
  for item in alist:
      time += item[0]
      if time > item[1]:
        return "No"
  return "Yes"

print(detect(new_list))
Buggy code:
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = list(zip(B, A))
C.sort()
B, A = zip(*C)
t = 0
for c in C:
    t += c[1]
    if t <= c[0]:
        continue
    else:
        print('no')
        exit()
print('yes')


Fixed code:
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = list(zip(B, A))
C.sort()
B, A = zip(*C)
t = 0
for c in C:
    t += c[1]
    if t <= c[0]:
        continue
    else:
        print('No')
        exit()
print('Yes')
Buggy code:
N=input()
X=[list(map(int,input().split())) for i in range(N)]
X=sorted(X,key=lambda x:x[1])
s=0
t=0
for i in range(N):
  s+=X[i][0]
  if s>X[i][1]:
    print("No")
    break
  else:
    t+=1
if t==N:
  print("Yes")
    

Fixed code:
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
X=sorted(X,key=lambda x:x[1])
s=0
t=0
for i in range(N):
  s+=X[i][0]
  if s>X[i][1]:
    print("No")
    break
  else:
    t+=1
if t==N:
  print("Yes")
Buggy code:
from sys import
input = sys.stdin.readline

n = int(input())
task = []
time_total = [-1 for i in range(n)]
for i in range(n):
    task.append([int(i) for i in input().split()])
task_sorted = sorted(task, key = lambda x:x[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]
for i in range(n):
    if time_total[i] > task_sorted[i][1]:
        print("No")
        exit()
print("Yes")

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

n = int(input())
task = []
time_total = [-1 for i in range(n)]
for i in range(n):
    task.append([int(i) for i in input().split()])
task_sorted = sorted(task, key = lambda x:x[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]
for i in range(n):
    if time_total[i] > task_sorted[i][1]:
        print("No")
        sys.exit()
print("Yes")
Buggy code:
n = int(input())

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

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

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

print(ab)

ws = 0

for i in range(n):
	ws += ab[i][0]
	if ws > ab[i][1]:
		print('No')
		break
else:
	print('Yes')

Fixed code:
n = int(input())

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

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

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

ws = 0

for i in range(n):
	ws += ab[i][0]
	if ws > ab[i][1]:
		print('No')
		break
else:
	print('Yes')
Buggy code:
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]

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

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


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

ab =sorted(ab, key = lambda x:x[1])
ans = 0
for i in ab:
    ans+=i[0]
    if ans > i[1]:
        print("No")
        exit()
print("Yes")
Buggy 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)

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

if result:
    print("Yes")
else:
    print("No")
Buggy code:
N=int(input())
W=[]
for i in range(N):
    a,b=map(int,input().split())
    W.append([b-a,a,b])
W.sort()
ans=0
for i in range(N):
    ans+=W[i][1]
    if ans > W[i][2]:
        print("No")
        exit()
print("Yes")


Fixed code:
N=int(input())
W=[]
for i in range(N):
    a,b=map(int,input().split())
    W.append([b,a])
W.sort()
ans=0
for i in range(N):
    ans+=W[i][1]
    if ans > W[i][0]:
        print("No")
        exit()
print("Yes")
Buggy code:
n=int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
#print(ab)
#print(b)
k=0
for t in range(n):
    k+=ab[n-1-t][0]
    #print([k,answer])
    if k>ab[n-1-t][1]:
        answer=answer*0
if answer==1:
    print('Yes')
else:
    print('No')

Fixed code:
n=int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
#print(ab)
k=0
answer=1
for t in range(n):
    k+=ab[t][0]
    #print([k,answer])
    if k>ab[t][1]:
        answer=answer*0
if answer==1:
    print('Yes')
else:
    print('No')
Buggy code:
N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab, key=lambda x: x[1])
for i in range(N - 1):
    if ab[i][1] < ab[i][0]:
        print("No")
        exit()
    ab[i + 1][0] += ab[i][0]
print("Yes")


Fixed code:
N = int(input())
ab = [[0, 0]] + [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab, key=lambda x: x[1])
for i in range(len(ab) - 1):
    ab[i + 1][0] += ab[i][0]
    if ab[i + 1][1] < ab[i + 1][0]:
        print("No")
        exit()

print("Yes")