Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, -(-h//A)]

S.sort()
print()
cnt = 0

for i in range(N):
    if S[i][1] <= 0:
        continue
    cnt += S[i][1]
    dmg = S[i][1]
    max_X = S[i][0] + D*2
    for j in range(i+1, N):
        if S[j][0] > max_X:
            break
        S[j][1] -= dmg

print(cnt)


Fixed submission:
from collections import deque
import math

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
atack = deque()
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, h]

S.sort()
cnt = 0
dmg = 0
for i in range(N):
    while atack:
        if atack[0][0] < S[i][0]:
            x, d = atack.popleft()
            dmg -= d
        else:
            break

    if S[i][1] <= dmg:
        continue
    bomb = math.ceil((S[i][1]-dmg)/A)
    atack.append([S[i][0]+2*D, A*bomb])
    cnt += bomb
    dmg += A*bomb

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
for i in range(N):
    x, h = map(int, input().split())
    if h % A == 0:
        h //= A
    else:
        h = h//A + 1
    S[i] = [x, h]

S.sort()
print()
cnt = 0

for i in range(N):
    if S[i][1] <= 0:
        continue
    cnt += S[i][1]
    dmg = S[i][1]
    max_X = S[i][0] + D*2
    for j in range(i+1, N):
        if S[j][0] > max_X:
            break
        S[j][1] -= dmg

print(cnt)


Fixed submission:
from collections import deque
import math

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
atack = deque()
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, h]

S.sort()
cnt = 0
dmg = 0
for i in range(N):
    while atack:
        if atack[0][0] < S[i][0]:
            x, d = atack.popleft()
            dmg -= d
        else:
            break

    if S[i][1] <= dmg:
        continue
    bomb = math.ceil((S[i][1]-dmg)/A)
    atack.append([S[i][0]+2*D, A*bomb])
    cnt += bomb
    dmg += A*bomb

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
for i in range(N):
    x, h = map(int, input().split())
    if h % A == 0:
        h //= A
    else:
        h = h//A + 1
    S[i] = [x, h]

S.sort()
cnt = 0

for i in range(N):
    if S[i][1] <= 0:
        continue
    cnt += S[i][1]
    dmg = S[i][1]
    max_X = S[i][0] + D*2
    for j in range(i+1, N):
        if S[j][0] > max_X:
            break
        S[j][1] -= dmg

print(cnt)


Fixed submission:
from collections import deque
import math

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
atack = deque()
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, h]

S.sort()
cnt = 0
dmg = 0
for i in range(N):
    while atack:
        if atack[0][0] < S[i][0]:
            x, d = atack.popleft()
            dmg -= d
        else:
            break

    if S[i][1] <= dmg:
        continue
    bomb = math.ceil((S[i][1]-dmg)/A)
    atack.append([S[i][0]+2*D, A*bomb])
    cnt += bomb
    dmg += A*bomb

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

S.sort()
cnt = 0

for i, item in enumerate(S):
    if item[1] <= 0:
        continue
    if item[1] % A == 0:
        dmg = item[1]
        cnt += item[1] // A
    else:
        dmg = A * (item[1]//A + 1)
        cnt += item[1]//A + 1
    max_X = item[0] + D*2
    for j in range(i+1, N):
        if S[j][0] > max_X:
            break
        S[j][1] -= dmg

print(cnt)


Fixed submission:
from collections import deque
import math

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
atack = deque()
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, h]

S.sort()
cnt = 0
dmg = 0
for i in range(N):
    while atack:
        if atack[0][0] < S[i][0]:
            x, d = atack.popleft()
            dmg -= d
        else:
            break

    if S[i][1] <= dmg:
        continue
    bomb = math.ceil((S[i][1]-dmg)/A)
    atack.append([S[i][0]+2*D, A*bomb])
    cnt += bomb
    dmg += A*bomb

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

S.sort()
cnt = 0

for i in range(N):
    if S[i][1] <= 0:
        continue
    if S[i][1] % A == 0:
        dmg = S[i][1]
        cnt += S[i][1] // A
    else:
        dmg = A * (S[i][1]//A + 1)
        cnt += S[i][1]//A + 1
    max_X = S[i][0] + D*2
    for j in range(i+1, N):
        if S[j][0] > max_X:
            break
        S[j][1] -= dmg

print(cnt)


Fixed submission:
from collections import deque
import math

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
atack = deque()
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, h]

S.sort()
cnt = 0
dmg = 0
for i in range(N):
    while atack:
        if atack[0][0] < S[i][0]:
            x, d = atack.popleft()
            dmg -= d
        else:
            break

    if S[i][1] <= dmg:
        continue
    bomb = math.ceil((S[i][1]-dmg)/A)
    atack.append([S[i][0]+2*D, A*bomb])
    cnt += bomb
    dmg += A*bomb

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

S.sort()
cnt = 0

for i in range(N):
    if S[i][1] <= 0:
        continue
    if S[i][1] % A == 0:
        dmg = S[i][1]
        cnt += S[i][1] // A
    else:
        dmg = A * (S[i][1]//A + 1)
        cnt += S[i][1]//A + 1
    max_X = S[i][0] + D*2
    j = i + 1
    while j < N:
        if S[j][0] > max_X:
            break
        S[j][1] -= dmg
        j += 1

print(cnt)


Fixed submission:
from collections import deque
import math

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
atack = deque()
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, h]

S.sort()
cnt = 0
dmg = 0
for i in range(N):
    while atack:
        if atack[0][0] < S[i][0]:
            x, d = atack.popleft()
            dmg -= d
        else:
            break

    if S[i][1] <= dmg:
        continue
    bomb = math.ceil((S[i][1]-dmg)/A)
    atack.append([S[i][0]+2*D, A*bomb])
    cnt += bomb
    dmg += A*bomb

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, D, A = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

S.sort()
cnt = 0

for i in range(N):
    if S[i][1] <= 0:
        continue
    if S[i][1] % A == 0:
        dmg = S[i][1]
        cnt += S[i][1] // A
    else:
        dmg = A * (S[i][1]//A + 1)
        cnt += S[i][1]//A + 1
    max_X = S[i][0] + D*2
    j = i + 1
    while j < N:
        if S[j][0] > max_X:
            break
        S[j][1] -= dmg
        j += 1

print(cnt)


Fixed submission:
from collections import deque
import math

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
atack = deque()
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, h]

S.sort()
cnt = 0
dmg = 0
for i in range(N):
    while atack:
        if atack[0][0] < S[i][0]:
            x, d = atack.popleft()
            dmg -= d
        else:
            break

    if S[i][1] <= dmg:
        continue
    bomb = math.ceil((S[i][1]-dmg)/A)
    atack.append([S[i][0]+2*D, A*bomb])
    cnt += bomb
    dmg += A*bomb

print(cnt)