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

def main():
    N,D,A = map(int,readline().split())
    m = map(int,read().split())
    X,H = map(list,zip(*sorted(zip(m,m))))
    count = 0
    for i in range(N):
        if H[i] > 0:
            bomb = (H[i]+A-1)//A
            count += bomb
            damage = bomb * A
            for j in range(i,N):
                if X[j] <= X[i] + 2*D:
                    H[j] -= damage
                else:
                    break

    print(count)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N,D,A = map(int,readline().split())
    m = map(int,read().split())
    X,H = zip(*sorted(zip(m,m)))
    
    over = [-1]*N
    tmp=0
    for i in range(N):
      while(tmp<N and X[i]+D*2>=X[tmp]):
        tmp += 1
      over[i] = tmp
    reset = [0]*N
    
    ans = 0
    dam = 0
    for i in range(N):
      if i>0:
        reset[i] += reset[i-1]
      hp = H[i]-dam+reset[i]
      if hp > 0:
        bomb = (hp+A-1)//A
        ans += bomb
        dam += bomb * A
        if(over[i]<N):
          reset[over[i]] += bomb * A

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def main():
    N,D,A = LI()
    M = []
    for i in range(N):
        M.append(LI())
    M.sort(key = lambda x: x[0])
    
    count = 0
    for i in range(N):
        if M[i][1] > 0:
            bomb = (M[i][1]+A-1)//A
            count += bomb
            damage = bomb * A
            for j in range(i,N):
                if M[j][0] <= M[i][0] + 2*D:
                    M[j][1] -= damage
                else:
                    break

    print(count)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N,D,A = map(int,readline().split())
    m = map(int,read().split())
    X,H = zip(*sorted(zip(m,m)))
    
    over = [-1]*N
    tmp=0
    for i in range(N):
      while(tmp<N and X[i]+D*2>=X[tmp]):
        tmp += 1
      over[i] = tmp
    reset = [0]*N
    
    ans = 0
    dam = 0
    for i in range(N):
      if i>0:
        reset[i] += reset[i-1]
      hp = H[i]-dam+reset[i]
      if hp > 0:
        bomb = (hp+A-1)//A
        ans += bomb
        dam += bomb * A
        if(over[i]<N):
          reset[over[i]] += bomb * A

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

N,D,A = LI()

def check(M):
    M_ = [[a,b] for a,b in M]
    count = 0
    for i in range(N):
        if M_[i][1] > 0:
            bomb = (M_[i][1]+A-1)//A
            count += bomb
            damage = bomb * A
            for j in range(i,N):
                if M_[j][0] <= M_[i][0] + 2*D:
                    M_[j][1] = max(0,M_[j][1] - damage)
                else:
                    break
    return count

def main():
    M = []
    for i in range(N):
        M.append(LI())
    M.sort(key = lambda x: x[0])

    print(check(M))

if __name__ == "__main__":
    main()


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N,D,A = map(int,readline().split())
    m = map(int,read().split())
    X,H = zip(*sorted(zip(m,m)))
    
    over = [-1]*N
    tmp=0
    for i in range(N):
      while(tmp<N and X[i]+D*2>=X[tmp]):
        tmp += 1
      over[i] = tmp
    reset = [0]*N
    
    ans = 0
    dam = 0
    for i in range(N):
      if i>0:
        reset[i] += reset[i-1]
      hp = H[i]-dam+reset[i]
      if hp > 0:
        bomb = (hp+A-1)//A
        ans += bomb
        dam += bomb * A
        if(over[i]<N):
          reset[over[i]] += bomb * A

    print(ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

N,D,A = LI()

def check(x,M):
    M_ = [[a,b] for a,b in M]
    count = 0
    for i in range(N):
        if M_[i][1] > 0:
            bomb = (M_[i][1]+A-1)//A
            count += bomb
            if count > x:
                return False

            damage = bomb * A
            for j in range(i,N):
                if M_[j][0] <= M_[i][0] + 2*D:
                    M_[j][1] = max(0,M_[j][1] - damage)
                else:
                    break
    return True

def main():
    M = []
    for i in range(N):
        M.append(LI())
    M.sort(key = lambda x: x[0])

    isNG = 0
    isOK = N*((10**9)+A-1)//A

    while(isNG+1 != isOK):
        mid = (isNG+isOK)//2
        if check(mid,M):
            isOK = mid
        else:
            isNG = mid
    print(isOK)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N,D,A = map(int,readline().split())
    m = map(int,read().split())
    X,H = zip(*sorted(zip(m,m)))
    
    over = [-1]*N
    tmp=0
    for i in range(N):
      while(tmp<N and X[i]+D*2>=X[tmp]):
        tmp += 1
      over[i] = tmp
    reset = [0]*N
    
    ans = 0
    dam = 0
    for i in range(N):
      if i>0:
        reset[i] += reset[i-1]
      hp = H[i]-dam+reset[i]
      if hp > 0:
        bomb = (hp+A-1)//A
        ans += bomb
        dam += bomb * A
        if(over[i]<N):
          reset[over[i]] += bomb * A

    print(ans)

if __name__ == "__main__":
    main()