Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,d,a = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l.sort()
    count = 0
    import math

    i = 0
    

    while True:
        sn = i
        s = l[i][0]
        s += 2*d
        mi = math.ceil(l[i][1]/a)
        count += mi
        b = mi*a
        l1 = 0
        while i < n and l[i][0] <= s:
            
            l[i][1] -= b
            if l[i][1] > 0:
                if l1 == 0:
                    l1 = i
            i += 1
            
        if l1 > 0:
            i = l1
        else:
            if i == n:
                print(count)
                exit()
    
if __name__ == "__main__":
    main()



Fixed submission:
def main():
    n,d,a = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l.sort()
    count = 0
    from collections import deque

    i = 0
    area = deque([])
    damage = deque([])
    total_damage = 0
    count = 0
    ans = 0
    for pos,hp in l:
        while area:
            ar = area[0]
            if ar < pos:
                area.popleft()
                power = damage.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            count = (hp-total_damage+a-1)//a
            ans += count
            total_damage += count*a
            area.append(pos+2*d)
            damage.append(count*a)

    print(ans)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,d,a = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l.sort()
    count = 0
    import math

    i = 0
    

    while True:
        sn = i
        s = l[i][0]
        mi = math.ceil(l[i][1]/a)
        count += mi
        
        l1 = 0
        while i < n and l[i][0] <= s+2*d:
            
            l[i][1] -= mi*a
            if l[i][1] > 0:
                if l1 == 0:
                    l1 = i
            i += 1
            
        if l1 > 0:
            i = l1
        else:
            if i == n:
                print(count)
                exit()
    
if __name__ == "__main__":
    main()



Fixed submission:
def main():
    n,d,a = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l.sort()
    count = 0
    from collections import deque

    i = 0
    area = deque([])
    damage = deque([])
    total_damage = 0
    count = 0
    ans = 0
    for pos,hp in l:
        while area:
            ar = area[0]
            if ar < pos:
                area.popleft()
                power = damage.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            count = (hp-total_damage+a-1)//a
            ans += count
            total_damage += count*a
            area.append(pos+2*d)
            damage.append(count*a)

    print(ans)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,d,a = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l.sort()
    count = 0
    import math
    import bisect
    i = 0
    l1 = []

    while i < n:
        sn = i
        s = l[i][0]
        mi = math.ceil(l[i][1]/a)
        count += mi
        l1 =[]
        while i < n and l[i][0] <= s+2*d:
            
            l[i][1] -= mi*a
            if l[i][1] > 0:
                l1.append(i)
            i += 1
            
        if len(l1) > 0:
            i = l1[0]
        else:
            if i == n:
                print(count)
                exit()
    
if __name__ == "__main__":
    main()



Fixed submission:
def main():
    n,d,a = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l.sort()
    count = 0
    from collections import deque

    i = 0
    area = deque([])
    damage = deque([])
    total_damage = 0
    count = 0
    ans = 0
    for pos,hp in l:
        while area:
            ar = area[0]
            if ar < pos:
                area.popleft()
                power = damage.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            count = (hp-total_damage+a-1)//a
            ans += count
            total_damage += count*a
            area.append(pos+2*d)
            damage.append(count*a)

    print(ans)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,d,a = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
count = 0
import math
import bisect
i = 0
l1 = []

while i < n:
    sn = i
    s = l[i][0]
    mi = math.ceil(l[i][1]/a)
    count += mi
    l1 =[]
    while i < n and l[i][0] <= s+2*d:
        
        l[i][1] -= mi*a
        if l[i][1] > 0:
            l1.append(i)
        i += 1
        
    if len(l1) > 0:
        i = l1[0]
    else:
        if i == n:
            print(count)
            exit()
    




Fixed submission:
def main():
    n,d,a = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l.sort()
    count = 0
    from collections import deque

    i = 0
    area = deque([])
    damage = deque([])
    total_damage = 0
    count = 0
    ans = 0
    for pos,hp in l:
        while area:
            ar = area[0]
            if ar < pos:
                area.popleft()
                power = damage.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            count = (hp-total_damage+a-1)//a
            ans += count
            total_damage += count*a
            area.append(pos+2*d)
            damage.append(count*a)

    print(ans)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n,d,a = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
count = 0
import math
i = 0
while i < n:
    sn = i
    s = l[i][0]
    mi = math.ceil(l[i][1]/a)
    count += mi
    
    while i < n and l[i][0] <= s+2*d:
        
        l[i][1] -= mi*a
        i += 1
        
    for j in range(sn,i+1):
        if j >= n:
            print(count)
            exit()
        if l[j][1] > 0:
            i = j
            
            break

print(count)   


Fixed submission:
def main():
    n,d,a = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l.sort()
    count = 0
    from collections import deque

    i = 0
    area = deque([])
    damage = deque([])
    total_damage = 0
    count = 0
    ans = 0
    for pos,hp in l:
        while area:
            ar = area[0]
            if ar < pos:
                area.popleft()
                power = damage.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            count = (hp-total_damage+a-1)//a
            ans += count
            total_damage += count*a
            area.append(pos+2*d)
            damage.append(count*a)

    print(ans)
if __name__ == "__main__":
    main()