Buggy python submission (verdict: Time Limit Exceeded):
n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key = lambda x:x[0])

target = 0
cnt = 0
while target < n:
    x, h = xh[target]
    atk_end = x + d + d
    atk_cnt = (h + a - 1) // a
    atk_dmg = a * atk_cnt
    cnt += atk_cnt
    for i in range(target, n):
        if xh[i][0] > atk_end:
            break
        xh[i][1] -= atk_dmg
    while xh[target][1] < 1:
        target += 1
        if target >= n:
            break

print(cnt)



Fixed submission:
import math
from collections import deque

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
xh = deque(xh)

xh_field = deque()

cnt = 0
now_damage = 0
while xh:
    pos, hp = xh.popleft()
    if xh_field:
        while (xh_field and xh_field[0][0] < pos) :
            now_damage -= a * xh_field[0][1]
            xh_field.popleft() 
    if hp <= now_damage:
        pass
    elif hp > now_damage:
        atk_cnt = math.ceil((hp - now_damage) / a)
        cnt += atk_cnt
        now_damage += atk_cnt * a
        xh_field.append((2*d + pos, atk_cnt))        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key = lambda x:x[0])
xh = deque(xh)

cnt = 0
while xh:
    x, h = xh.popleft()
    if h < 1:
        continue
    atk_end = x + d + d
    atk_cnt = (h + a - 1) // a
    cnt += atk_cnt
    for i in range(len(xh)):
        if xh[i][0] > atk_end:
            break
        xh[i][1] -= a * atk_cnt

print(cnt)

Fixed submission:
import math
from collections import deque

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
xh = deque(xh)

xh_field = deque()

cnt = 0
now_damage = 0
while xh:
    pos, hp = xh.popleft()
    if xh_field:
        while (xh_field and xh_field[0][0] < pos) :
            now_damage -= a * xh_field[0][1]
            xh_field.popleft() 
    if hp <= now_damage:
        pass
    elif hp > now_damage:
        atk_cnt = math.ceil((hp - now_damage) / a)
        cnt += atk_cnt
        now_damage += atk_cnt * a
        xh_field.append((2*d + pos, atk_cnt))        
print(cnt)

Buggy python submission (verdict: Runtime Error):
n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key = lambda x:x[0])

cnt = 0
while len(xh) != 0:
    x, h = xh.pop(0)
    atk_end = x + d + d
    atk_cnt = (h + a - 1) // a
    cnt += atk_cnt
    for i in range(len(xh)):
        if xh[i][0] > atk_end:
            break
        xh[i][1] -= a * atk_cnt
    while xh[0][1] < 1:
        xh.pop(0)
        if len(xh) == 0:
            break

print(cnt)

Fixed submission:
import math
from collections import deque

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
xh = deque(xh)

xh_field = deque()

cnt = 0
now_damage = 0
while xh:
    pos, hp = xh.popleft()
    if xh_field:
        while (xh_field and xh_field[0][0] < pos) :
            now_damage -= a * xh_field[0][1]
            xh_field.popleft() 
    if hp <= now_damage:
        pass
    elif hp > now_damage:
        atk_cnt = math.ceil((hp - now_damage) / a)
        cnt += atk_cnt
        now_damage += atk_cnt * a
        xh_field.append((2*d + pos, atk_cnt))        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort()

target = 0
cnt = 0
while target < n:
    x, h = xh[target]
    atk_end = x + d + d
    atk_cnt = (h + a - 1) // a
    cnt += atk_cnt
    for i in range(target, n):
        if xh[i][0] > atk_end:
            break
        xh[i][1] -= a * atk_cnt
        if xh[i][1] < 1 and i == target+1:
            target += 1
    # while xh[target][1] < 1:
    #     target += 1
    #     if target >= n:
    #         break

print(cnt)

Fixed submission:
import math
from collections import deque

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
xh = deque(xh)

xh_field = deque()

cnt = 0
now_damage = 0
while xh:
    pos, hp = xh.popleft()
    if xh_field:
        while (xh_field and xh_field[0][0] < pos) :
            now_damage -= a * xh_field[0][1]
            xh_field.popleft() 
    if hp <= now_damage:
        pass
    elif hp > now_damage:
        atk_cnt = math.ceil((hp - now_damage) / a)
        cnt += atk_cnt
        now_damage += atk_cnt * a
        xh_field.append((2*d + pos, atk_cnt))        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort()

target = 0
cnt = 0
while target < n:
    x, h = xh[target]
    atk_end = x + d + d
    atk_cnt = (h + a - 1) // a
    cnt += atk_cnt
    for i in range(target, n):
        if xh[i][0] > atk_end:
            break
        xh[i][1] -= a * atk_cnt
    while xh[target][1] < 1:
        target += 1
        if target >= n:
            break

print(cnt)

Fixed submission:
import math
from collections import deque

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort(key=lambda x:x[0])
xh = deque(xh)

xh_field = deque()

cnt = 0
now_damage = 0
while xh:
    pos, hp = xh.popleft()
    if xh_field:
        while (xh_field and xh_field[0][0] < pos) :
            now_damage -= a * xh_field[0][1]
            xh_field.popleft() 
    if hp <= now_damage:
        pass
    elif hp > now_damage:
        atk_cnt = math.ceil((hp - now_damage) / a)
        cnt += atk_cnt
        now_damage += atk_cnt * a
        xh_field.append((2*d + pos, atk_cnt))        
print(cnt)