Buggy python submission (verdict: Runtime Error):
from bisect import bisect_right
import sys
input = sys.stdin.readline

class BIT:
    '''
    区間加算BIT(区間加算・区間合計取得) 
    '''
    def __init__(self, N):
        # 添え字0は使えないので1-indexとして扱う
        N += 1
        self.N = N
        self.data0 = [0] * N
        self.data1 = [0] * N

    def _add(self, data, k, x):
        k += 1
        while k < self.N:
            data[k] += x
            k += k & -k

    def _get(self, data, k):
        k += 1
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def add(self, l, r, x):
        # 区間[l,r)に値xを追加

        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, -x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)

    def query(self, l, r):
        # 区間[l,r)の和を取得
        return self._get(self.data1, r-1) * (r-1) + self._get(self.data0, r-1) \
            - self._get(self.data1, l-1) * (l-1) - self._get(self.data0, l-1)

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

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]

    bit = BIT(N)
    for i in range(N):
        H[i] -= bit.query(i, i+1)
        if H[i] <= 0:
            continue
        cnt = H[i] // A if H[i] % A == 0 else H[i] // A + 1
        index = bisect_right(X, X[i] + 2 * D)
        bit.add(i, index+1, cnt * A)
        ans += cnt

    print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect_right
import sys
input = sys.stdin.readline

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

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]
    ans = 0
    ok = [False] * N
    S = [0] * (N + 1)
    for i in range(N):
        if S[i] < H[i]:
            cnt = (H[i] - S[i]) // A if (H[i] - S[i]) % A == 0 else (H[i] - S[i]) // A + 1
            ans += cnt
            search_max = bisect_right(X, X[i] + 2 * D)
            S[i] += cnt * A
            S[search_max] -= cnt * A
        
        S[i+1] += S[i]

    print(ans)



if __name__ == "__main__":
    main()

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

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

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]
    ans = 0
    ok = [False] * N


    for i in range(N):
        if ok[i]:
            continue
        cnt = H[i] // A if H[i] % A == 0 else H[i] // A + 1
        ans += cnt
        ok[i] = True
        search_max = bisect_right(X, X[i] + 2 * D) - 1
        for j in range(min(i+1,N),min(search_max+1,N)):
            if ok[j]:
                continue
            H[j] -= cnt * A
            if H[j] <= 0:
                ok[j] = True
    
    print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect_right
import sys
input = sys.stdin.readline

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

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]
    ans = 0
    ok = [False] * N
    S = [0] * (N + 1)
    for i in range(N):
        if S[i] < H[i]:
            cnt = (H[i] - S[i]) // A if (H[i] - S[i]) % A == 0 else (H[i] - S[i]) // A + 1
            ans += cnt
            search_max = bisect_right(X, X[i] + 2 * D)
            S[i] += cnt * A
            S[search_max] -= cnt * A
        
        S[i+1] += S[i]

    print(ans)



if __name__ == "__main__":
    main()

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

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

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]
    ans = 0
    ok = [False] * N
    for i in range(N):
        if ok[i]:
            continue
        cnt = H[i] // A if H[i] % A == 0 else H[i] // A + 1
        ans += cnt
        ok[i] = True
        search_max = bisect_right(X, X[i] + 2 * D) - 1
        for j in range(min(i+1,N),min(search_max+1,N)):
            if ok[j]:
                continue
            H[j] -= cnt * A
            if H[j] <= 0:
                ok[j] = True
    
    print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect_right
import sys
input = sys.stdin.readline

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

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]
    ans = 0
    ok = [False] * N
    S = [0] * (N + 1)
    for i in range(N):
        if S[i] < H[i]:
            cnt = (H[i] - S[i]) // A if (H[i] - S[i]) % A == 0 else (H[i] - S[i]) // A + 1
            ans += cnt
            search_max = bisect_right(X, X[i] + 2 * D)
            S[i] += cnt * A
            S[search_max] -= cnt * A
        
        S[i+1] += S[i]

    print(ans)



if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, D, A = map(int, input().split())
    B = []
    for i in range(N):
        X, H = map(int, input().split())
        B.append([X,H])

    B.sort()
    ans = 0
    ok = [False] * N
    for i in range(N):
        if ok[i]:
            continue
        cnt = B[i][1] // A if B[i][1] % A == 0 else B[i][1] // A + 1
        ans += cnt
        B[i][1] = 0
        ok[i] = True
        for j in range(min(i+1,N),N):
            if ok[j]:
                continue
            if B[j][0] <= B[i][0] + 2 * D:
                B[j][1] -= cnt * A
                if B[j][1] <= 0:
                    ok[j] = True
            else:
                break
    
    print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect_right
import sys
input = sys.stdin.readline

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

    for i in range(N):
        x, h = map(int, input().split())
        B.append((x,h))

    B.sort()
    X = [0] * N
    H = [0] * N
    for i in range(N):
        X[i], H[i] = B[i]
    ans = 0
    ok = [False] * N
    S = [0] * (N + 1)
    for i in range(N):
        if S[i] < H[i]:
            cnt = (H[i] - S[i]) // A if (H[i] - S[i]) % A == 0 else (H[i] - S[i]) // A + 1
            ans += cnt
            search_max = bisect_right(X, X[i] + 2 * D)
            S[i] += cnt * A
            S[search_max] -= cnt * A
        
        S[i+1] += S[i]

    print(ans)



if __name__ == "__main__":
    main()