Problem p02788 (python)

Fixed submission:
import bisect

n, d, a = map(int, input().split())
xh = []
for i in range(n):
    xh.append(list(map(int, input().split())))
xh.sort()
x = [xh[i][0] for i in range(n)]
h = [xh[i][1] for i in range(n)]
count = 0
min_x = 0
acm = [0] * (n + 1)
dif = [0] * (n + 1)
while min_x < n:
    place = x[min_x] + d
    num = (h[min_x] - acm[min_x + 1] - 1) // a + 1
    count += num
    dif[min_x] += num
    dif[bisect.bisect(x, place + d)] -= num
    for i in range(min_x, bisect.bisect(x, place + d)):
        acm[i + 1] = acm[i] + dif[i] * a
        if acm[i + 1] >= h[i]:
            min_x += 1
            continue
        else:
            break
print(count)

Buggy submission (verdict: Runtime Error):
import bisect

n, d, a = map(int, input().split())
xh = []
x_list = []
for i in range(n):
    x, h = map(int, input().split())
    xh.append([x, h])
    x_list.append(x)
xh.sort()
x.sort()
count = 0
min_x = 0
sum_h = sum([xh[i][1] for i in range(n)])
while sum_h > 0:
    flag = True
    place = xh[min_x][0] + d
    num = (xh[min_x][1] - 1) // a + 1
    count += num
    for i in range(min_x, bisect.bisect(x_list, place + d)):
        new_h = max(0, xh[i][1] - a * num)
        sum_h -= (xh[i][1] - new_h)
        if new_h == 0:
            if flag == True:
                min_x += 1
        else:
            flag = False
        xh[i][1] = new_h
print(count)

Buggy submission (verdict: Runtime Error):
import bisect

n, d, a = map(int, input().split())
xh = []
for i in range(n):
    xh.append(list(map(int, input().split())))
xh.sort()
count = 0
min_x = 0
x = [xh[i][0] for i in range(n)]
sum_h = sum([xh[i][1] for i in range(n)])
while sum_h > 0:
    flag == True
    place = xh[min_x][0] + d
    num = (xh[min_x][1] - 1) // a + 1
    count += num
    for i in range(min_x, bisect.bisect(x, place + d)):
        new_h = max(0, xh[i][1] - a * num)
        sum_h -= (xh[i][1] - new_h)
        if new_h == 0:
            if flag == True:
                min_x += 1
        else:
            flag = False
        xh[i][1] = new_h
print(count)

Buggy submission (verdict: Runtime Error):
import bisect

n, d, a = map(int, input().split())
xh = []
for i in range(n):
    xh.append(list(map(int, input().split())))
xh.sort()
count = 0
min_x = 0
x = [xh[i][0] for i in range(n)]
sum_h = sum([xh[i][1] for i in range(n)])
while sum_h > 0:
    place = xh[min_x][0] + d
    num = (xh[min_x][1] - 1) // a + 1
    count += num
    edge = bisect.bisect(x, place + d)
    for i in range(min_x, edge):
        new_h = max(0, xh[i][1] - a * num)
        sum_h -= (xh[i][1] - new_h)
        if new_h == 0:
            min_x += 1
        xh[i][1] = new_h
print(count)

Buggy submission (verdict: Runtime Error):
import bisect

n, d, a = map(int, input().split())
xh = []
for i in range(n):
    xh.append(list(map(int, input().split())))
xh.sort()
count = 0
min_x = 0
x = [xh[i][0] for i in range(n)]
while sum([xh[i][1] for i in range(n)]):
    place = xh[min_x][0] + d
    num = (xh[min_x][1] - 1) // a + 1
    count += num
    edge = bisect.bisect(x, place + d)
    for i in range(min_x, edge):
        new_h = max(0, xh[i][1] - a * num)
        if new_h == 0:
            min_x += 1
        xh[i][1] = new_h
print(count)

Buggy submission (verdict: Runtime Error):
n, d, a = map(int, input().split())
xh = []
for i in range(n):
    xh.append(list(map(int, input().split())))
xh.sort()
count = 0
min_x = 0
while sum([xh[i][1] for i in range(n)]):
    place = xh[min_x][0] + d
    num = (xh[min_x][1] - 1) // a + 1
    count += num
    check = min_x
    while xh[check][0] <= place + d:
        new_h = max(0, xh[check][1] - a * num)
        if new_h == 0:
            min_x += 1
        xh[check][1] = new_h
        check += 1
        if check == n:
            break
print(count)