Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
    
INF = 10**15
M = 2*10**4

dp = [[INF]*(M+1) for i in range(N+1)]

for i in range(N+1):
    dp[i][0] = 0

for i in range(N):
    A,B = AB[i]
    for j in range(A):
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
    for j in range(H)
        dp[i+1][j+A] = min(dp[i][j+A], dp[i+1][j]+B, dp[i+1][j+A])
        
ans = INF
for i in range(H,M):
    ans = min(ans,dp[N][i])
print(ans)

Fixed submission:
N,D,A = map(int,input().split())
XH = []
X = []

for i in range(N):
    x,h = map(int,input().split())
    XH.append([x,h,0])
    X.append(x)
    
XH.sort(key = lambda a:a[0])
XH.append([float('inf'),0,0])
X.sort()
X.append(float('inf'))

import bisect
ans = 0

for i in range(N):
    x,h,k = XH[i]
    dk = max(-(-(h-k*A)//A),0)
    #print(x,h,k,dk)
    ans += dk
    
    XH[i][2] += dk
    j = bisect.bisect_right(X,x+2*D)
    XH[j][2] -= dk

    XH[i+1][2] += XH[i][2]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
INF = 10**15
dp = [[INF]*(2*10**4+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
 
for i in range(N):
    for j in range(1,2*10**4+1):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j-AB[i][0]]+AB[i][1])
        
ans = float('inf')
for i in range(H,2*10**4+1):
    ans = min(ans,dp[N][i])
print(ans)

Fixed submission:
N,D,A = map(int,input().split())
XH = []
X = []

for i in range(N):
    x,h = map(int,input().split())
    XH.append([x,h,0])
    X.append(x)
    
XH.sort(key = lambda a:a[0])
XH.append([float('inf'),0,0])
X.sort()
X.append(float('inf'))

import bisect
ans = 0

for i in range(N):
    x,h,k = XH[i]
    dk = max(-(-(h-k*A)//A),0)
    #print(x,h,k,dk)
    ans += dk
    
    XH[i][2] += dk
    j = bisect.bisect_right(X,x+2*D)
    XH[j][2] -= dk

    XH[i+1][2] += XH[i][2]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])

dp = [[float('inf')]*(H+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(N):
    for j in range(H):
        dp[i+1][min(j+AB[i][0],H)] = min(dp[i][min(j+AB[i][0],H)],dp[i+1][j]+AB[i][1],dp[i+1][min(j+AB[i][0],H)])
        
print(dp[N][H])

Fixed submission:
N,D,A = map(int,input().split())
XH = []
X = []

for i in range(N):
    x,h = map(int,input().split())
    XH.append([x,h,0])
    X.append(x)
    
XH.sort(key = lambda a:a[0])
XH.append([float('inf'),0,0])
X.sort()
X.append(float('inf'))

import bisect
ans = 0

for i in range(N):
    x,h,k = XH[i]
    dk = max(-(-(h-k*A)//A),0)
    #print(x,h,k,dk)
    ans += dk
    
    XH[i][2] += dk
    j = bisect.bisect_right(X,x+2*D)
    XH[j][2] -= dk

    XH[i+1][2] += XH[i][2]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])

dp = [[float('inf')]*(H+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(N):
    for j in range(H):
        dp[i+1][min(j+AB[i][0],H)] = min(dp[i][min(j+AB[i][0],H)],dp[i+1][j]+AB[i][1],dp[i+1][min(j+AB[i][0],H)])
        
print(dp[N][H])

Fixed submission:
N,D,A = map(int,input().split())
XH = []
X = []

for i in range(N):
    x,h = map(int,input().split())
    XH.append([x,h,0])
    X.append(x)
    
XH.sort(key = lambda a:a[0])
XH.append([float('inf'),0,0])
X.sort()
X.append(float('inf'))

import bisect
ans = 0

for i in range(N):
    x,h,k = XH[i]
    dk = max(-(-(h-k*A)//A),0)
    #print(x,h,k,dk)
    ans += dk
    
    XH[i][2] += dk
    j = bisect.bisect_right(X,x+2*D)
    XH[j][2] -= dk

    XH[i+1][2] += XH[i][2]
    
print(ans)