Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
import numpy as np

N, D, A = map(int, input().split())
M = np.array([list(map(int, input().split())) for i in range(N)])

M = M[np.argsort(M[:, 0])]
X = M[:, 0]
H = M[:, 1]
ans = 0
for i in range(N):
    if H[i] <= 0:
        continue
    blast_r = X[i] + 2 * D
    max_j = bisect_right(X, blast_r, i + 1)
    c = (H[i] + A - 1) // A
    ans += c
    if i + 1 < max_j:
        H[i + 1:max_j] -= A * c
print(ans)


Fixed submission:
from collections import deque

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
diff = 0
q = deque()
for i in range(N):
    Xi, Hi = M[i]
    while len(q) > 0 and q[0][0] < Xi:
        diff += q.popleft()[1]
    Hi += diff
    if Hi <= 0:
        continue
    c = (Hi + A - 1) // A
    ans += c
    diff -= A * c
    q.append((Xi + 2 * D, A * c))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
for i in range(N):
    if H[i] <= 0:
        continue
    blast_r = X[i] + 2 * D
    max_j = bisect_right(X, blast_r, i + 1)
    c = (H[i] + A - 1) // A
    ans += c
    if i + 1 < max_j:
        H[i + 1:max_j] = [H[j] - A * c for j in range(i + 1, max_j)]
print(ans)


Fixed submission:
from collections import deque

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
diff = 0
q = deque()
for i in range(N):
    Xi, Hi = M[i]
    while len(q) > 0 and q[0][0] < Xi:
        diff += q.popleft()[1]
    Hi += diff
    if Hi <= 0:
        continue
    c = (Hi + A - 1) // A
    ans += c
    diff -= A * c
    q.append((Xi + 2 * D, A * c))
print(ans)

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

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
for i in range(N):
    if H[i] <= 0:
        continue
    blast_r = X[i] + 2 * D
    max_j = N
    for j in range(i + 1, N):
        if X[j] > blast_r:
            max_j = j
            break
    c = (H[i] + A - 1) // A
    ans += c
    if i + 1 < max_j:
        H[i + 1:max_j] = [H[j] - A * c for j in range(i + 1, max_j)]
print(ans)


Fixed submission:
from collections import deque

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
diff = 0
q = deque()
for i in range(N):
    Xi, Hi = M[i]
    while len(q) > 0 and q[0][0] < Xi:
        diff += q.popleft()[1]
    Hi += diff
    if Hi <= 0:
        continue
    c = (Hi + A - 1) // A
    ans += c
    diff -= A * c
    q.append((Xi + 2 * D, A * c))
print(ans)

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

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
for i in range(N):
    if H[i] <= 0:
        continue
    blast_r = X[i] + 2 * D
    max_j = N
    for j in range(i + 1, N):
        if X[j] > blast_r:
            max_j = j
            break
    c = (H[i] + A - 1) // A
    ans += c
    if i + 1 < max_j:
        H[i + 1:max_j] = [H[j] - A * c for j in range(i + 1, max_j)]
print(ans)


Fixed submission:
from collections import deque

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
diff = 0
q = deque()
for i in range(N):
    Xi, Hi = M[i]
    while len(q) > 0 and q[0][0] < Xi:
        diff += q.popleft()[1]
    Hi += diff
    if Hi <= 0:
        continue
    c = (Hi + A - 1) // A
    ans += c
    diff -= A * c
    q.append((Xi + 2 * D, A * c))
print(ans)

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

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
for i in range(N):
    if H[i] <= 0:
        continue
    blast_r = X[i] + 2 * D
    max_j = N
    for j in range(i + 1, N):
        if X[j] > blast_r:
            max_j = j
            break
    c = (H[i] + A - 1) // A
    ans += c
    if i + 1 < max_j:
        H[i + 1:max_j] = [H[j] - A * c for j in range(i + 1, max_j)]
print(ans)


Fixed submission:
from collections import deque

N, D, A = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

M.sort()
X = [M[i][0] for i in range(N)]
H = [M[i][1] for i in range(N)]
ans = 0
diff = 0
q = deque()
for i in range(N):
    Xi, Hi = M[i]
    while len(q) > 0 and q[0][0] < Xi:
        diff += q.popleft()[1]
    Hi += diff
    if Hi <= 0:
        continue
    c = (Hi + A - 1) // A
    ans += c
    diff -= A * c
    q.append((Xi + 2 * D, A * c))
print(ans)