Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappop, heappush
from math import ceil
import sys

input = sys.stdin.readline


def main():
    n, d, a = map(int, input().split())
    hp = [list(map(int, input().split())) for _ in range(n)]
    heapify(hp)

    ans = 0

    while hp:
        left = heappop(hp)
        cnt = ceil(left[1] / a)
        li = []
        while hp and hp[0][0] <= left[0] + 2 * d:
            nxt = heappop(hp)
            if nxt[1] - a * cnt > 0:
                li.append([nxt[0], nxt[1] - a * cnt])

        for e in li:
            heappush(hp, e)

        ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from heapq import heapify, heappush, heappop
from math import ceil

REAL = 0
UNREAL = 1

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

hp = []
for x, h in xh:
    heappush(hp, [x, REAL, h])

bomb_acm = 0
ans = 0
while hp:
    x, r, h = heappop(hp)
    if r == REAL:
        if h > bomb_acm:
            left = h - bomb_acm
            bomb_cnt = ceil(left / a)
            hp_dis = a * bomb_cnt
            bomb_acm += hp_dis
            heappush(hp, [x + 2 * d, UNREAL, hp_dis])
            ans += bomb_cnt

    else: # r == UNREAL
        bomb_acm -= h

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappop, heappush
from math import ceil

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
hp = xh
heapify(hp)

ans = 0

while hp:
    left = heappop(hp)
    cnt = ceil(left[1] / a)
    li = []
    while hp and hp[0][0] <= left[0] + 2 * d:
        nxt = heappop(hp)
        if nxt[1] - a * cnt > 0:
            li.append([nxt[0], nxt[1] - a * cnt])

    for e in li:
        heappush(hp, e)

    ans += cnt

print(ans)


Fixed submission:
from heapq import heapify, heappush, heappop
from math import ceil

REAL = 0
UNREAL = 1

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

hp = []
for x, h in xh:
    heappush(hp, [x, REAL, h])

bomb_acm = 0
ans = 0
while hp:
    x, r, h = heappop(hp)
    if r == REAL:
        if h > bomb_acm:
            left = h - bomb_acm
            bomb_cnt = ceil(left / a)
            hp_dis = a * bomb_cnt
            bomb_acm += hp_dis
            heappush(hp, [x + 2 * d, UNREAL, hp_dis])
            ans += bomb_cnt

    else: # r == UNREAL
        bomb_acm -= h

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappop, heappush
from math import ceil

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
hp = xh
heapify(hp)

ans = 0

while hp:
    left = heappop(hp)
    cnt = ceil(left[1] / a)
    li = []
    while hp and hp[0][0] <= left[0] + 2 * d:
        nxt = heappop(hp)
        if nxt[1] - a * cnt > 0:
            li.append([nxt[0], nxt[1] - a * cnt])

    for e in li:
        heappush(hp, e)

    ans += cnt

print(ans)


Fixed submission:
from heapq import heapify, heappush, heappop
from math import ceil

REAL = 0
UNREAL = 1

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

hp = []
for x, h in xh:
    heappush(hp, [x, REAL, h])

bomb_acm = 0
ans = 0
while hp:
    x, r, h = heappop(hp)
    if r == REAL:
        if h > bomb_acm:
            left = h - bomb_acm
            bomb_cnt = ceil(left / a)
            hp_dis = a * bomb_cnt
            bomb_acm += hp_dis
            heappush(hp, [x + 2 * d, UNREAL, hp_dis])
            ans += bomb_cnt

    else: # r == UNREAL
        bomb_acm -= h

print(ans)