Buggy python submission (verdict: Time Limit Exceeded):
import math


def main():
        
    N,D,A = map(int, input().split())

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

    xh.sort()

    ans = 0
    for i in range(N):
        if xh[i][1] <= 0:
            continue


        
        cnt = math.ceil(xh[i][1] / A)
        ans += cnt
        xh[i][1] = 0

        if cnt == 0:
            continue

        d = cnt*A
        for j in range(i+1, N):

            if xh[j][0] > xh[i][0] + 2*D:
                break
            xh[j][1] -= d


    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import math
from collections import deque

def main():
        
    N,D,A = map(int, input().split())

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

    xh.sort()

    ans = 0
    q = deque()
    dmg = 0
    for i in range(N):
        # 過去に使った爆弾で、現在地点まで攻撃が届かないものは効果切れにする
        while q and q[0][0] < xh[i][0]:
            _, d = q.popleft()
            dmg -= d

        # それまでの攻撃でその地点の敵が死んでいるので、その敵に対しては新たに爆弾を使わない
        if xh[i][1] - dmg <= 0:
            continue

        remaining = xh[i][1] - dmg

        cnt = math.ceil(remaining / A)
        ans += cnt
        dmg += cnt * A
        # その敵に対して爆弾を使ったので、追加
        q.append((xh[i][0] + 2*D, cnt*A))


    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math


def main():
        
    N,D,A = map(int, input().split())

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

    xh.sort()

    ans = 0
    for i in range(N):
        if xh[i][1] <= 0:
            continue


        
        cnt = math.ceil(xh[i][1] / A)
        ans += cnt
        xh[i][1] = 0

        if cnt == 0:
            continue

        d = cnt*A
        for j in range(i+1, N):

            if xh[j][0] > xh[i][0] + 2*D:
                break
            xh[j][1] -= d


    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import math
from collections import deque

def main():
        
    N,D,A = map(int, input().split())

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

    xh.sort()

    ans = 0
    q = deque()
    dmg = 0
    for i in range(N):
        # 過去に使った爆弾で、現在地点まで攻撃が届かないものは効果切れにする
        while q and q[0][0] < xh[i][0]:
            _, d = q.popleft()
            dmg -= d

        # それまでの攻撃でその地点の敵が死んでいるので、その敵に対しては新たに爆弾を使わない
        if xh[i][1] - dmg <= 0:
            continue

        remaining = xh[i][1] - dmg

        cnt = math.ceil(remaining / A)
        ans += cnt
        dmg += cnt * A
        # その敵に対して爆弾を使ったので、追加
        q.append((xh[i][0] + 2*D, cnt*A))


    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math


def main():
        
    N,D,A = map(int, input().split())

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

    xh.sort()

    ans = 0
    for i in range(N):
        if xh[i][1] <= 0:
            continue
        
        cnt = math.ceil(xh[i][1] / A)
        ans += cnt
        xh[i][1] = 0

        if cnt == 0:
            continue

        for j in range(i+1, N):

            if xh[j][0] > xh[i][0] + 2*D:
                break
            xh[j][1] -= cnt*A

        #print(ans, xh)
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import math
from collections import deque

def main():
        
    N,D,A = map(int, input().split())

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

    xh.sort()

    ans = 0
    q = deque()
    dmg = 0
    for i in range(N):
        # 過去に使った爆弾で、現在地点まで攻撃が届かないものは効果切れにする
        while q and q[0][0] < xh[i][0]:
            _, d = q.popleft()
            dmg -= d

        # それまでの攻撃でその地点の敵が死んでいるので、その敵に対しては新たに爆弾を使わない
        if xh[i][1] - dmg <= 0:
            continue

        remaining = xh[i][1] - dmg

        cnt = math.ceil(remaining / A)
        ans += cnt
        dmg += cnt * A
        # その敵に対して爆弾を使ったので、追加
        q.append((xh[i][0] + 2*D, cnt*A))


    print(ans)

if __name__ == "__main__":
    main()