Buggy python submission (verdict: Time Limit Exceeded):
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
for l in range(N):
  if xh[l][1]==0:
    #print(l)
    continue
  la = (xh[l][1]+A-1)//A
  xh[l][1]=0
  r=l
  for _ in range(N):
    if l<N and r<N and 2*D>xh[r][0]-xh[l][0]:
      if 2*D<abs(xh[l][0]-xh[min(r+1,N-1)][0]):
        break
      else:
        r+=1
        if r<N:
          xh[r][1]=max(0,xh[r][1]-la*A)
    else:
      break
  ans +=la
  if r==l:
    r+=1
print(ans)


Fixed submission:
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
d = [0]*(N+1)
for l in range(N):
  if d[l]<xh[l][1]:
    la = (xh[l][1]-d[l]+A-1)//A
    for _ in range(N):
      if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]:
        r+=1
      else:
        break
    ans += la
    d[l]+=la*A
    d[r]-=la*A
  d[l+1]+=d[l]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
for l in range(N):
  if xh[l][1]==0:
    #print(l)
    continue
  la = (xh[l][1]+A-1)//A
  xh[l][1]=0
  r=l
  while l<N and r<N and 2*D>xh[r][0]-xh[l][0]:
    #mi=min(mi,(xh[r][1]+A-1)//A)
    #xh[r][1]=max(0,xh[r][1]-la*A)
    if 2*D<abs(xh[l][0]-xh[min(r+1,N-1)][0]):
      break
    else:
      r+=1
      if r<N:
        xh[r][1]=max(0,xh[r][1]-la*A)
        #print(xh)
  ans +=la
  if r==l:
    r+=1
print(ans)


Fixed submission:
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
d = [0]*(N+1)
for l in range(N):
  if d[l]<xh[l][1]:
    la = (xh[l][1]-d[l]+A-1)//A
    for _ in range(N):
      if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]:
        r+=1
      else:
        break
    ans += la
    d[l]+=la*A
    d[r]-=la*A
  d[l+1]+=d[l]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
for l in range(N):
  if xh[l][1]==0:
    continue
  for _ in range(N):
    if  l<N and r<N and 2*D>xh[r][0]-xh[l][0]:
      if 2*D<abs(xh[l][0]-xh[min(r+1,N-1)][0]):
        break
      else:
        r+=1
  #print(1,l,r)
  la = (xh[l][1]+A-1)//A
  ans +=(xh[l][1]+A-1)//A
  for i in range(l,min(r+1,N)):
    xh[i][1]=max(0,xh[i][1]-la*A)
    #print(xh[i][1],i)
  if r==l:
    r+=1
print(ans)


Fixed submission:
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
d = [0]*(N+1)
for l in range(N):
  if d[l]<xh[l][1]:
    la = (xh[l][1]-d[l]+A-1)//A
    for _ in range(N):
      if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]:
        r+=1
      else:
        break
    ans += la
    d[l]+=la*A
    d[r]-=la*A
  d[l+1]+=d[l]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
for l in range(N):
  if xh[l][1]==0:
    continue
  while l<N and r<N and 2*D>xh[r][0]-xh[l][0]:
    #mi=min(mi,(xh[r][1]+A-1)//A)
    if 2*D<abs(xh[l][0]-xh[min(r+1,N-1)][0]):
      break
    else:
      r+=1
  #print(1,l,r)
  la = (xh[l][1]+A-1)//A
  ans +=(xh[l][1]+A-1)//A
  for i in range(l,min(r+1,N)):
    xh[i][1]=max(0,xh[i][1]-la*A)
    #print(xh[i][1],i)
  if r==l:
    r+=1
print(ans)

Fixed submission:
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
d = [0]*(N+1)
for l in range(N):
  if d[l]<xh[l][1]:
    la = (xh[l][1]-d[l]+A-1)//A
    for _ in range(N):
      if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]:
        r+=1
      else:
        break
    ans += la
    d[l]+=la*A
    d[r]-=la*A
  d[l+1]+=d[l]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
for l in range(N):
  if xh[l][1]==0:
    continue
  while l<N and r<N and 2*D>xh[r][0]-xh[l][0]:
    #mi=min(mi,(xh[r][1]+A-1)//A)
    if 2*D<abs(xh[l][0]-xh[min(r+1,N-1)][0]):
      break
    else:
      r+=1
  #print(1,l,r)
  la = (xh[l][1]+A-1)//A
  ans +=(xh[l][1]+A-1)//A
  for i in range(l,min(r+1,N)):
    xh[i][1]=max(0,xh[i][1]-la*A)
    #print(xh[i][1],i)
  if r==l:
    r+=1
print(ans)

Fixed submission:
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
d = [0]*(N+1)
for l in range(N):
  if d[l]<xh[l][1]:
    la = (xh[l][1]-d[l]+A-1)//A
    for _ in range(N):
      if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]:
        r+=1
      else:
        break
    ans += la
    d[l]+=la*A
    d[r]-=la*A
  d[l+1]+=d[l]
print(ans)

Buggy python submission (verdict: Runtime Error):
import bisect
H,N = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
dp = [[10**18]*(10**4+1) for _ in range(N+1)]
for i in range(N+1):
  dp[i][0]=0
mi=10**9
for i in range(N):
  for w in range(10**4+1):
    dp[i+1][w]=min(dp[i+1][w],dp[i][w])
    if w-AB[i][0]>=0:
      dp[i+1][w]=min(dp[i+1][w],dp[i + 1][w - AB[i][0]] + AB[i][1])
for i in range(H,10**4+1):
  mi = min(mi,dp[N][i])
print(mi)

Fixed submission:
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
d = [0]*(N+1)
for l in range(N):
  if d[l]<xh[l][1]:
    la = (xh[l][1]-d[l]+A-1)//A
    for _ in range(N):
      if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]:
        r+=1
      else:
        break
    ans += la
    d[l]+=la*A
    d[r]-=la*A
  d[l+1]+=d[l]
print(ans)