Buggy python submission (verdict: Time Limit Exceeded):
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)


Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

def main():
  input = sys.stdin.readline
  N, D, A = list(map(int, input().split()))
  XH = [list(map(int, input().split())) for _ in range(N)]

  XH.sort()
  H = [XH[i][1] for i in range(N)]

  T = segTree(N)
  T.set(H)

  p = 0
  ans = 0
  for i in range(N):
    for j in range(p + 1, N):
      if XH[j][0] > XH[i][0] + D * 2:
        p = j - 1
        break
      else:
        p = N - 1
    t = (T.get(i, i) - 1) // A + 1
    if t <= 0: continue
    ans += t
    T.add(i, p, -t * A)

  print(ans)

main()

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

def main():
  input = sys.stdin.readline
  N, D, A = list(map(int, input().split()))
  XH = [list(map(int, input().split())) for _ in range(N)]

  XH.sort()
  H = [XH[i][1] for i in range(N)]

  T = segTree(N)
  T.set(H)

  p = 0
  ans = 0
  for i in range(N):
    for j in range(p + 1, N):
      if XH[j][0] > XH[i][0] + D * 2:
        p = j - 1
        break
      else:
        p = N - 1
    t = (T.get(i, i) - 1) // A + 1
    if t <= 0: continue
    ans += t
    T.add(i, p, -t * A)

  print(ans)

main()

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = float("inf")
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1
  
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1
  
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1
  
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 1e10
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1
  
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 1e10
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1
  
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 1e10
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    s.downs(x, 0, 0, s.N - 1)
  def downs(s, x, k, kl, kr):
    v = s.D[k]
    s.T[k] += v
    s.D[k] = 0
    t = (kl + kr) // 2
    if 2 * k + 1 >= 2 * s.N - 1: return
    s.D[2 * k + 1] += v
    s.D[2 * k + 2] += v
    if x <= t:
      s.downs(x, 2 * k + 1, kl, t)
    else:
      s.downs(x, 2 * k + 2, t + 1, kr)
      

  
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 1e10
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r:
      s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    s.downs(x, 0, 0, s.N - 1)
  def downs(s, x, k, kl, kr):
    v = s.D[k]
    s.T[k] += v
    s.D[k] = 0
    t = (kl + kr) // 2
    if 2 * k + 1 >= 2 * s.N - 1: return
    s.D[2 * k + 1] += v
    s.D[2 * k + 2] += v
    if x <= t:
      s.downs(x, 2 * k + 1, kl, t)
    else:
      s.downs(x, 2 * k + 2, t + 1, kr)
      

  
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

class segTree:
  inf = 1e10
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    s.down(r)
    return s.gets(l, r, 0, 0, s.N - 1)
  def gets(s, l, r, k, kl, kr):
    if l <= kl and r >= kr:
      return s.T[k]
    t = (kl + kr) // 2
    if l > t:
      return s.gets(l, r, 2 * k + 2, t + 1,kr)
    if r < t + 1:
      return s.gets(l, r , 2 * k + 1, kl, t)
    return s.do(s.gets(l, r , 2 * k + 1, kl,t),
              s.gets(l, r , 2 * k + 2, t + 1, kr))
  def add(s, l, r, v):
    s.adds(l, r, v, 0, 0, s.N - 1)
  def adds(s, l, r, v, k, kl, kr):
    if k >= 2 * s.N - 1: return
    if l <= kl and kr <= r:
      s.D[k] += v
      return
    if kl <= r and l <= kr:
      t = (kl + kr) // 2
      s.adds(l, r, v, 2 * k + 1, kl, t)
      s.adds(l, r, v, 2 * k + 2, t + 1, kr)
  def down(s, x):
    s.downs(x, 0, 0, s.N - 1)
  def downs(s, x, k, kl, kr):
    v = s.D[k]
    s.T[k] += v
    s.D[k] = 0
    t = (kl + kr) // 2
    if 2 * k + 1 >= 2 * s.N - 1: return
    s.D[2 * k + 1] += v
    s.D[2 * k + 2] += v
    if x <= t:
      s.downs(x, 2 * k + 1, kl, t)
    else:
      s.downs(x, 2 * k + 2, t + 1, kr)
      

  
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)

Fixed submission:
class segTree:
  inf = 10 ** 9
  def __init__(s, num):
    s.N = 1
    while s.N < num:
      s.N *= 2
    s.T = [s.inf] * (2 * s.N - 1)
    s.D = [0] * (2 * s.N - 1)
  def do(s, l, r):
    #最小値
    return min(l, r)
  def set(s, L):
    for i in range(len(L)):
      s.update(i, L[i])
  def update(s, x, v):
    k = x + s.N - 1
    s.T[k] = v
    while k > 0:
      k = (k - 1) // 2
      s.T[k] = s.do(s.T[2*k+1], s.T[2*k+2])
  def get(s, l, r):
    s.down(l)
    if l != r: s.down(r)
    ans = s.inf
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and r >= kr: ans = s.do(ans, s.T[k])
      else:
        t = (kl + kr) // 2
        if l > t: S.append([2 * k + 2, t + 1,kr])
        elif r < t + 1: S.append([2 * k + 1, kl, t])
        else: 
          S.append([2 * k + 2, t + 1,kr])
          S.append([2 * k + 1, kl, t])
    return ans
  def add(s, l, r, v):
    k, kl, kr = 0, 0, s.N - 1
    S = [[k, kl, kr]]
    while S:
      k, kl, kr = S.pop()
      if l <= kl and kr <= r:
        s.D[k] += v
        continue
      if k >= s.N: continue
      if kl <= r and l <= kr:
        t = (kl + kr) // 2
        S.append([2 * k + 1, kl, t])
        S.append([2 * k + 2, t + 1, kr])

  def down(s, x):
    k, kl, kr = 0, 0, s.N - 1
    while True:
      v = s.D[k]
      s.T[k] += v
      s.D[k] = 0
      t = (kl + kr) // 2
      if 2 * k + 1 >= 2 * s.N - 1: return
      s.D[2 * k + 1] += v
      s.D[2 * k + 2] += v
      if x <= t:
        k = 2 * k + 1
        kr = t
      else:
        k = 2 * k + 2
        kl = t + 1

import sys
input = sys.stdin.readline
N, D, A = list(map(int, input().split()))
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
H = [XH[i][1] for i in range(N)]

T = segTree(N)
T.set(H)

p = 0
ans = 0
for i in range(N):
  for j in range(p + 1, N):
    if XH[j][0] > XH[i][0] + D * 2:
      p = j - 1
      break
    else:
      p = N - 1
  t = (T.get(i, i) - 1) // A + 1
  if t <= 0: continue
  ans += t
  T.add(i, p, -t * A)

print(ans)