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

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)

# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
    attack[i] += attack[i-1]
    if attack[i] >= h[x[i]]:
        continue

    if (h[x[i]] - attack[i]) % a == 0:
        j = (h[x[i]] - attack[i]) // a
    else:
        j = (h[x[i]] - attack[i]) // a + 1
    attack[i] += a * j
    ans += j

    # 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
    # start <= y <= stop
    start = i + 1
    stop = n
    k = stop - start + 1
    while k > 1:
        if x[start + k//2 - 1] <= x[i] + 2*d:
            start += k//2
        else:
            stop = start + k//2 - 1
        k = stop - start + 1
    attack[start] -= a * j

print(ans)

Fixed submission:
import sys
def input():
    return sys.stdin.readline().strip()

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)

# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
    attack[i] += attack[i-1]
    if attack[i] >= h[x[i]]:
        continue

    if (h[x[i]] - attack[i]) % a == 0:
        j = (h[x[i]] - attack[i]) // a
    else:
        j = (h[x[i]] - attack[i]) // a + 1
    attack[i] += a * j
    ans += j

    # 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
    # start <= y <= stop
    start = i + 1
    stop = n
    k = stop - start + 1
    while k > 1:
        if x[start + k//2 - 1] <= x[i] + 2*d:
            start += k//2
        else:
            stop = start + k//2 - 1
        k = stop - start + 1
    attack[start] -= a * j

print(ans)

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

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()

ans = 0
attack = [0 for _ in range(n)]
for i in range(n):
    attack[i] += attack[i-1]
    if attack[i] >= h[x[i]]:
        continue

    if (h[x[i]] - attack[i]) % a == 0:
        k = (h[x[i]] - attack[i]) // a
    else:
        k = (h[x[i]] - attack[i]) // a + 1
    attack[i] += a * k
    ans += k

    for j in range(i+1, n):
        if x[j] > x[i] + 2*d:
            attack[j] -= a * k
            break

print(ans)

Fixed submission:
import sys
def input():
    return sys.stdin.readline().strip()

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)

# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
    attack[i] += attack[i-1]
    if attack[i] >= h[x[i]]:
        continue

    if (h[x[i]] - attack[i]) % a == 0:
        j = (h[x[i]] - attack[i]) // a
    else:
        j = (h[x[i]] - attack[i]) // a + 1
    attack[i] += a * j
    ans += j

    # 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
    # start <= y <= stop
    start = i + 1
    stop = n
    k = stop - start + 1
    while k > 1:
        if x[start + k//2 - 1] <= x[i] + 2*d:
            start += k//2
        else:
            stop = start + k//2 - 1
        k = stop - start + 1
    attack[start] -= a * j

print(ans)

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

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()

ans = 0
todo = [0 for _ in range(n)] #未処理は0、処理済は1
for i in range(n):
    if todo[i] == 0:
        if h[x[i]] % a == 0:
            k = h[x[i]] // a
        else:
            k = h[x[i]] // a + 1
        ans += k
        todo[i] = 1
        for j in range(i+1, n):
            if x[j] <= x[i] + 2*d:
                if todo[j] == 0:
                    if h[x[j]] <= a * k:
                        todo[j] = 1
                    else:
                        h[x[j]] -= a * k
            else:
                break

print(ans)

Fixed submission:
import sys
def input():
    return sys.stdin.readline().strip()

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)

# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
    attack[i] += attack[i-1]
    if attack[i] >= h[x[i]]:
        continue

    if (h[x[i]] - attack[i]) % a == 0:
        j = (h[x[i]] - attack[i]) // a
    else:
        j = (h[x[i]] - attack[i]) // a + 1
    attack[i] += a * j
    ans += j

    # 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
    # start <= y <= stop
    start = i + 1
    stop = n
    k = stop - start + 1
    while k > 1:
        if x[start + k//2 - 1] <= x[i] + 2*d:
            start += k//2
        else:
            stop = start + k//2 - 1
        k = stop - start + 1
    attack[start] -= a * j

print(ans)

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

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()

ans = 0
todo = [0 for _ in range(n)] #未処理は0、処理済は1
for i in range(n):
    if todo[i] == 0:
        if h[x[i]] % a == 0:
            k = h[x[i]] // a
        else:
            k = h[x[i]] // a + 1
        ans += k
        todo[i] = 1
        for j in range(i+1, n):
            if x[j] <= x[i] + 2*d:
                if todo[j] == 0:
                    if h[x[j]] <= a * k:
                        todo[j] = 1
                    else:
                        h[x[j]] -= a * k
            else:
                break

print(ans)

Fixed submission:
import sys
def input():
    return sys.stdin.readline().strip()

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)

# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
    attack[i] += attack[i-1]
    if attack[i] >= h[x[i]]:
        continue

    if (h[x[i]] - attack[i]) % a == 0:
        j = (h[x[i]] - attack[i]) // a
    else:
        j = (h[x[i]] - attack[i]) // a + 1
    attack[i] += a * j
    ans += j

    # 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
    # start <= y <= stop
    start = i + 1
    stop = n
    k = stop - start + 1
    while k > 1:
        if x[start + k//2 - 1] <= x[i] + 2*d:
            start += k//2
        else:
            stop = start + k//2 - 1
        k = stop - start + 1
    attack[start] -= a * j

print(ans)

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

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()

ans = 0
todo = [0 for _ in range(n)] #未処理は0、処理済は1
for i in range(n):
    if todo[i] == 0:
        if h[x[i]] % a == 0:
            k = h[x[i]] // a
        else:
            k = h[x[i]] // a + 1
        ans += k
        todo[i] = 1
        for j in range(i+1, n):
            if x[j] <= x[i] + 2*d:
                if todo[j] == 0:
                    if h[x[j]] <= a * k:
                        todo[j] = 1
                    else:
                        h[x[j]] -= a * k
            else:
                break

print(ans)

Fixed submission:
import sys
def input():
    return sys.stdin.readline().strip()

n, d, a = map(int, input().split())

x = []
h = {} # x:h
for _ in range(n):
    i, j = map(int, input().split())
    x.append(i)
    h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)

# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
    attack[i] += attack[i-1]
    if attack[i] >= h[x[i]]:
        continue

    if (h[x[i]] - attack[i]) % a == 0:
        j = (h[x[i]] - attack[i]) // a
    else:
        j = (h[x[i]] - attack[i]) // a + 1
    attack[i] += a * j
    ans += j

    # 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
    # start <= y <= stop
    start = i + 1
    stop = n
    k = stop - start + 1
    while k > 1:
        if x[start + k//2 - 1] <= x[i] + 2*d:
            start += k//2
        else:
            stop = start + k//2 - 1
        k = stop - start + 1
    attack[start] -= a * j

print(ans)