Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N,D,A = map(int,input().split())
  import numpy as np
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  X = [xh[0] for xh in XH]
  H = np.array([xh[1] for xh in XH])
  ans = 0
  l=[0]*N
  x = X[0]
  j = 0
  h = H[0]
  b = (h+A-1)//A
  ans += b
  while True:
    if j+1>=N:
      break
    if X[j+1]<=x+2*D:
      j+=1
    else:
      break
  H[0:j+1:]-=b*A
  l[0]=j
  for i in range(1,N):
    x = X[i]
    j = max(i,l[i-1])
    h = H[i]
    if h<=0:
      continue
    else:
      b = (h+A-1)//A
      ans += b
      while True:
        if j+1>=N:
          break
        if X[j+1]<=x+2*D:
          j+=1
        else:
          break
      H[i:j+1:]-=b*A
  print(ans)
main()

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  def syaku(j,x,D):
    while True:
      if j+1>=N:
        break
      if XH[j+1][0]<=x+2*D:
        j+=1
      else:
        break
    return j
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  l=[0]*N
  x = XH[0][0]
  j = 0
  l[0]=syaku(j,x,D)
  for i in range(1,N):
    x = XH[i][0]
    j = l[i-1]
    l[i]=syaku(j,x,D)
  H = [xh[1] for xh in XH]
  for i,a in enumerate(l):
    h = H[i]
    if h<=0:
      continue
    else:
      b = (h+A-1)//A
      ans += b
      y = b*A
      for j in range(i,a+1):
        H[j]-=y
  print(ans)
main()

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  def syaku(j,x,D):
    while True:
      if j+1>=N:
        break
      if XH[j+1][0]<=x+2*D:
        j+=1
      else:
        break
    return j
  N,D,A = map(int,input().split())
  import numpy as np
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  l=[0]*N
  x = XH[0][0]
  j = 0
  l[0]=syaku(j,x,D)
  for i in range(1,N):
    x = XH[i][0]
    j = l[i-1]
    l[i]=syaku(j,x,D)
  H = np.array([xh[1] for xh in XH])
  for i,a in enumerate(l):
    h = H[i]
    if h<=0:
      continue
    else:
      b = (h+A-1)//A
      ans += b
      H[i:a+1:]-=b*A
  print(ans)
main()

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  def binary_search(left,right,x):
    while left+1!=right:
      mid = (right+left)//2
      if XH[mid][0]<=x+2*D:
        left = mid
      else:
        right = mid
    return left
  
  def cal(h,i,a,ans):
    b = math.ceil(h/A)
    ans += b
    H[i:a+1:]-=b*A
    return ans
  
  N,D,A = map(int,input().split())
  import numpy as np
  import math
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  l=[0]*N
  x = XH[0][0]
  l[0]=binary_search(0,N,x)
  for i in range(1,N):
    x = XH[i][0]
    l[i]=binary_search(l[i-1],N,x)
  H = np.array([xh[1] for xh in XH])
  for i,a in enumerate(l):
    h = H[i]
    if h<=0:
      continue
    else:
      ans = cal(h,i,a,ans)
  print(ans)
  
main()

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N,D,A = map(int,input().split())
  import numpy as np
  import math
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  l=[0]*N
  x = XH[0][0]
  left = 0
  right = N
  while left+1!=right:
    mid = (right+left)//2
    if XH[mid][0]<=x+2*D:
      left = mid
    else:
      right = mid
  l[0]=left
  for i in range(1,N):
    x = XH[i][0]
    right = N
    left = l[i-1]
    while left+1!=right:
      mid = (right+left)//2
      if XH[mid][0]<=x+2*D:
        left = mid
      else:
        right = mid
    l[i]=left
  H = np.array([xh[1] for xh in XH])
  for i,a in enumerate(l):
    h = H[i]
    if h<=0:
      continue
    else:
      b = math.ceil(h/A)
      ans += b
      H[i:a+1:]-=b*A
  print(ans)
  
main()

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,D,A = map(int,input().split())
import numpy as np
import math
XH = [list(map(int,input().split())) for _ in range(N)]
XH = sorted(XH)
ans = 0
l=[0]*N
x = XH[0][0]
left = 0
right = N
while left+1!=right:
  mid = (right+left)//2
  if XH[mid][0]<=x+2*D:
    left = mid
  else:
    right = mid
l[0]=left
for i in range(1,N):
  x = XH[i][0]
  right = N
  left = l[i-1]
  while left+1!=right:
    mid = (right+left)//2
    if XH[mid][0]<=x+2*D:
      left = mid
    else:
      right = mid
  l[i]=left
H = np.array([xh[1] for xh in XH])
for i,a in enumerate(l):
  h = H[i]
  if h<=0:
    continue
  else:
    b = math.ceil(h/A)
    ans += b
    H[i:a+1:]-=b*A
print(ans)

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
N,D,A = map(int,input().split())
import numpy as np
import math
XH = [list(map(int,input().split())) for _ in range(N)]
XH = sorted(XH)
ans = 0
l=[0]*N
x = XH[0][0]
j = 0
while True:
  if j+1>=N:
    break
  if XH[j+1][0]<=x+2*D:
    j+=1
  else:
    break
l[0]=j
for i in range(1,N):
  x = XH[i][0]
  j = l[i-1]
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  l[i]=j
H = np.array([xh[1] for xh in XH])
for i,a in enumerate(l):
  h = H[i]
  if h<=0:
    continue
  else:
    b = math.ceil(h/A)
    ans += b
    H[i:a+1:]-=b*A
print(ans)

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Runtime Error):
N,D,A = map(int,input().split())
import numpy as np
import math
XH = [list(map(int,input().split())) for _ in range(N)]
XH = sorted(XH)
ans = 0
ma = XH[-1][0]
l = np.array([0]*(ma+5))
for xh in XH:
  l[xh[0]]=xh[1]
  

for xh in XH:
  x = xh[0]
  if x+2*D<=ma:
    a = l[x]
    if a<=0:
      continue
    else:
      b = math.ceil(a/A)
      ans += b
      l[x:x+2*D+1:]-=b*A
  else:
    a = l[x]
    if a<=0:
      continue
    else:
      b=math.ceil(a/A)
      ans += b
      l[x::]-=b*A
      
print(ans)

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Runtime Error):
N,D,A = map(int,input().split())
import numpy as np
import math
XH = [list(map(int,input().split())) for _ in range(N)]
XH = sorted(XH)
ans = 0
ma = XH[-1][0]
l = np.array([0]*(ma+5))
for xh in XH:
  l[xh[0]]=xh[1]
  

for xh in XH:
  x = xh[0]
  if x+2*D<=ma:
    a = l[x]
    if a<=0:
      continue
    else:
      b = math.ceil(a/A)
      ans += b
      l[x:x+2*D+1:]-=b*a
  else:
    a = l[x]
    if a<=0:
      continue
    else:
      b=math.ceil(a/A)
      ans += b
      l[x::]-=b*a
      
print(ans)

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()

Buggy python submission (verdict: Runtime Error):
N,D,A = map(int,input().split())
import numpy as np
import math
XH = [list(map(int,input().split())) for _ in range(N)]
XH = sorted(XH)
ans = 0
ma = XH[-1][0]
l = np.array([0]*(ma+5))
for xh in XH:
  l[xh[0]]=xh[1]
  

for xh in XH:
  x = xh[0]
  if x+D<=ma:
    a = l[x]
    if a<=0:
      continue
    else:
      b = math.ceil(a/A)
      ans += b
      l[x:x+2*D+1:]-=b*a
  else:
    a = l[x]
    if a<=0:
      continue
    else:
      b=math.ceil(a/A)
      ans += b
      l[x::]-=b*a
      
print(ans)

Fixed submission:
def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()