Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

N =  int(readline())
HP = [tuple(map(int, readline().split())) for _ in range(N)]
HP.sort(key = lambda x: x[0] + x[1])
INF = 1<<64

dp = [0]
for i in range(N):
    hi, pi = HP[i]
    dp += [INF]
    for j in range(i+1, 0, -1):
        if dp[j-1] > hi:
            continue
        dp[j] = min(dp[j], dp[j-1]+pi)
for ans in range(N+1):
    if dp[ans] == INF:
        ans -= 1
        break
print(ans)



Fixed submission:
import sys
readline = sys.stdin.readline

N =  int(readline())
HP = [tuple(map(int, readline().split())) for _ in range(N)]
HP.sort(key = lambda x: x[0] + x[1])
INF = 1<<64

dp = [0]
for i in range(N):
    hi, pi = HP[i]
    dp += [INF]
    for j in range(i+1, 0, -1):
        if dp[j-1] > hi:
            continue
        dp[j] = min(dp[j], dp[j-1]+pi)
for ans in range(N+1):
    if dp[ans] == INF:
        ans -= 1
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

N =  int(readline())
HP = [tuple(map(int, readline().split())) for _ in range(N)]
HP.sort(key = lambda x: x[0] + x[1])
INF = 1<<64

dp = [0]
for i in range(N):
    hi, pi = HP[i]
    dp2 = dp[:] + [INF]
    for j in range(i+1):
        if dp[j] > hi:
            break
        dp2[j+1] = min(dp2[j+1], dp[j]+pi)

    dp = dp2[:]

for ans in range(N+1):
    if dp[ans] == INF:
        ans -= 1
        break
print(ans)



Fixed submission:
import sys
readline = sys.stdin.readline

N =  int(readline())
HP = [tuple(map(int, readline().split())) for _ in range(N)]
HP.sort(key = lambda x: x[0] + x[1])
INF = 1<<64

dp = [0]
for i in range(N):
    hi, pi = HP[i]
    dp += [INF]
    for j in range(i+1, 0, -1):
        if dp[j-1] > hi:
            continue
        dp[j] = min(dp[j], dp[j-1]+pi)
for ans in range(N+1):
    if dp[ans] == INF:
        ans -= 1
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

N =  int(readline())
HP = [tuple(map(int, readline().split())) for _ in range(N)]
HP.sort(key = sum)
INF = 10**18+3

dp = [0]
for i in range(N):
    hi, pi = HP[i]
    dp2 = dp[:] + [INF]
    for j in range(i+1):
        if dp[j] > hi:
            break
        dp2[j+1] = min(dp2[j+1], dp[j]+pi)

    dp = dp2[:]

for ans in range(N+1):
    if dp[ans] == INF:
        ans -= 1
        break
print(ans)



Fixed submission:
import sys
readline = sys.stdin.readline

N =  int(readline())
HP = [tuple(map(int, readline().split())) for _ in range(N)]
HP.sort(key = lambda x: x[0] + x[1])
INF = 1<<64

dp = [0]
for i in range(N):
    hi, pi = HP[i]
    dp += [INF]
    for j in range(i+1, 0, -1):
        if dp[j-1] > hi:
            continue
        dp[j] = min(dp[j], dp[j-1]+pi)
for ans in range(N+1):
    if dp[ans] == INF:
        ans -= 1
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

N =  int(readline())
HP = [tuple(map(int, readline().split())) for _ in range(N)]
HP.sort(key = sum)
INF = 10**18+3

dp = [INF]*(N+1)
dp[0] = 0

for i in range(N):
    hi, pi = HP[i]
    dp2 = dp[:]
    for j in range(N):
        if dp[j] > hi:
            break
        dp2[j+1] = min(dp2[j+1], dp[j]+pi)

    dp = dp2[:]

for ans in range(N+1):
    if dp[ans] == INF:
        ans -= 1
        break
print(ans)



Fixed submission:
import sys
readline = sys.stdin.readline

N =  int(readline())
HP = [tuple(map(int, readline().split())) for _ in range(N)]
HP.sort(key = lambda x: x[0] + x[1])
INF = 1<<64

dp = [0]
for i in range(N):
    hi, pi = HP[i]
    dp += [INF]
    for j in range(i+1, 0, -1):
        if dp[j-1] > hi:
            continue
        dp[j] = min(dp[j], dp[j-1]+pi)
for ans in range(N+1):
    if dp[ans] == INF:
        ans -= 1
        break
print(ans)