Problem:


Score : 600 points

Problem Statement

Silver Fox is fighting with N monsters.

The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.

Silver Fox can use bombs to attack the monsters.
Using a bomb at the coordinate x decreases the healths of all monsters between the coordinates x-D and x+D (inclusive) by A.
There is no way other than bombs to decrease the monster's health.

Silver Fox wins when all the monsters' healths become 0 or below.

Find the minimum number of bombs needed to win.

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq D \leq 10^9

1 \leq A \leq 10^9

0 \leq X_i \leq 10^9

1 \leq H_i \leq 10^9

X_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N D A
X_1 H_1
:
X_N H_N

Output

Print the minimum number of bombs needed to win.

Sample Input 1

3 3 2
1 2
5 4
9 2

Sample Output 1

2

First, let us use a bomb at the coordinate 4 to decrease the first and second monsters' health by 2.

Then, use a bomb at the coordinate 6 to decrease the second and third monsters' health by 2.

Now, all the monsters' healths are 0.
We cannot make all the monsters' health drop to 0 or below with just one bomb.

Sample Input 2

9 4 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5

Sample Output 2

5

We should use five bombs at the coordinate 5.

Sample Input 3

3 0 1
300000000 1000000000
100000000 1000000000
200000000 1000000000

Sample Output 3

3000000000

Watch out for overflow.



Sample input:
3 3 2
1 2
5 4
9 2


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,D,A = inputMap()
    D = 2*D
    XH = []
    for i in range(N):
        X,H = inputMap()
        XH.append((X,H))
        
    XH.sort()
    q = Queue()
    
    ans = 0
    hosei = 0
    for i,val in enumerate(XH):
        X,H = val
        
        tmp_len = q.size()
        for j in range(tmp_len):
            tmp = q.retnext()
            if tmp == None:
                break
            hanni_q,dame_q = q.retnext()
            if X > hanni_q:
                hosei += dame_q
                q.d()
            else:
                break
        
        H += hosei
        if H > 0:
            bakudan_int = -(-H // A)
            dame = bakudan_int * A
            hanni = X + D
            
            ans += bakudan_int
            hosei -= dame
            q.enqueue((hanni,dame))
    
    print(ans)
    
class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []
    
    def enqueue(self, e):
        self.queue.append(e)   
        return self.queue     
    
    def dequeue(self):
        try:
            qEl = self.queue[0]     
            del self.queue[0]     
            return qEl
        except IndexError: 
            return None
            
    def retnext(self):
        try:
            qEl = self.queue[0]
            return qEl
        except IndexError: 
            return None
            
    def d(self):
        del self.queue[0]     
            
    def size(self):
        return len(self.queue)
    
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,D,A = inputMap()
    D = 2*D
    XH = []
    for i in range(N):
        X,H = inputMap()
        XH.append((X,H))
        
    XH.sort()
    q = Queue()
    
    ans = 0
    hosei = 0
    for i,val in enumerate(XH):
        X,H = val
        
        tmp_len = q.size()
        for j in range(tmp_len):
            hanni_q,dame_q = q.retnext()
            if X > hanni_q:
                hosei += dame_q
                q.d()
            else:
                break
        
        H += hosei
        if H > 0:
            bakudan_int = -(-H // A)
            dame = bakudan_int * A
            hanni = X + D
            
            ans += bakudan_int
            hosei -= dame
            q.enqueue((hanni,dame))
    
    print(ans)
    
class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []
    
    def enqueue(self, e):
        self.queue.append(e)   
        return self.queue     
    
    def dequeue(self):
        try:
            qEl = self.queue[0]     
            del self.queue[0]     
            return qEl
        except IndexError: 
            return None
            
    def retnext(self):
        try:
            qEl = self.queue[0]
            return qEl
        except IndexError: 
            return None
            
    def d(self):
        del self.queue[0]     
            
    def size(self):
        return len(self.queue)
    
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,D,A = inputMap()
    D = 2*D
    XH = []
    for i in range(N):
        X,H = inputMap()
        XH.append((X,H))
        
    XH.sort()
    q = Queue()
    
    ans = 0
    hosei = 0
    for i,val in enumerate(XH):
        X,H = val
        
        tmp_len = q.size()
        for j in range(tmp_len):
            hanni_q,dame_q = q.retnext()
            if X > hanni_q:
                hosei += dame_q
                q.d()
        
        H += hosei
        if H > 0:
            bakudan_int = -(-H // A)
            dame = bakudan_int * A
            hanni = X + D
            
            ans += bakudan_int
            hosei -= dame
            q.enqueue((hanni,dame))
    
    print(ans)
    
class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []
    
    def enqueue(self, e):
        self.queue.append(e)   
        return self.queue     
    
    def dequeue(self):
        try:
            qEl = self.queue[0]     
            del self.queue[0]     
            return qEl
        except IndexError: 
            return None
            
    def retnext(self):
        try:
            qEl = self.queue[0]
            return qEl
        except IndexError: 
            return None
            
    def d(self):
        del self.queue[0]     
            
    def size(self):
        return len(self.queue)
    
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,D,A = inputMap()
    D = 2*D
    XH = []
    for i in range(N):
        X,H = inputMap()
        XH.append((X,H))
        
    XH.sort()
    q = Queue()
    
    ans = 0
    hosei = 0
    for i,val in enumerate(XH):
        X,H = val
        
        tmp_len = q.size()
        for j in range(tmp_len):
            hanni_q,dame_q = q.retnext()
            if X > hanni_q:
                hosei += dame_q
                q.dequeue()
        
        H += hosei
        if H > 0:
            bakudan_int = -(-H // A)
            dame = bakudan_int * A
            hanni = X + D
            
            ans += bakudan_int
            hosei -= dame
            q.enqueue((hanni,dame))
    
    print(ans)
    
class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []
    
    def enqueue(self, e):
        self.queue.append(e)   
        return self.queue     
    
    def dequeue(self):
        try:
            qEl = self.queue[0]     
            del self.queue[0]     
            return qEl
        except IndexError: 
            return None
            
    def retnext(self):
        try:
            qEl = self.queue[0]
            return qEl
        except IndexError: 
            return None
            
    def size(self):
        return len(self.queue)
    
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,D,A = inputMap()
    D = 2*D
    XH = []
    for i in range(N):
        X,H = inputMap()
        XH.append((X,H))
        
    XH.sort()
    q = Queue()
    
    ans = 0
    hosei = 0
    for i,val in enumerate(XH):
        X,H = val
        
        tmp_len = q.size()
        for j in range(tmp_len):
            hanni_q,dame_q = q.dequeue()
            if X > hanni_q:
                hosei += dame_q
            else:
                q.enqueue((hanni_q,dame_q))
        
        H += hosei
        if H > 0:
            bakudan_int = -(-H // A)
            dame = bakudan_int * A
            hanni = X + D
            
            ans += bakudan_int
            hosei -= dame
            q.enqueue((hanni,dame))
    
    print(ans)
    
class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []
    
    def enqueue(self, e):
        self.queue.append(e)   
        return self.queue     
    
    def dequeue(self):
        try:
            qEl = self.queue[0]     
            del self.queue[0]     
            return qEl
        except IndexError: 
            return None
            
    def size(self):
        return len(self.queue)
    
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# input
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

# process
XH.sort()
#print(XH)

ans = 0
for i in range(N):
    x, h = XH[i]
    if h <= 0:
        continue

    XH[i][1] = 0
    c = -(-h//A)
    ans += c

    dmg = A*c
    scp_end = x+D*2

    for j in range(i+1, N):
        xj, hj = XH[j]
        if xj <= scp_end:
            if hj > 0:
                XH[j][1] -= dmg
        else:
            break
    
#    print(XH)

# output
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,D,A = inputMap()
    D = 2*D
    XH = []
    for i in range(N):
        X,H = inputMap()
        XH.append((X,H))
        
    XH.sort()
    q = Queue()
    
    ans = 0
    for i,val in enumerate(XH):
        X,H = val
        
        tmp_len = q.size()
        #print(tmp_len)
        for j in range(tmp_len):
            hanni_q,dame_q = q.dequeue()
            #print((X,hanni_q))
            if X <= hanni_q:
                H -= dame_q
                q.enqueue((hanni_q,dame_q))
        
        if H > 0:
            bakudan_int = -(-H // A)
            dame = bakudan_int * A
            hanni = X + D
            
            ans += bakudan_int
            q.enqueue((hanni,dame))
    
    print(ans)
    
class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []
    
    def enqueue(self, e):
        self.queue.append(e)   
        return self.queue     
    
    def dequeue(self):
        try:
            qEl = self.queue[0]     
            del self.queue[0]     
            return qEl
        except IndexError: 
            return None
            
    def size(self):
        return len(self.queue)
    
    
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
import math

# input
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

# process
XH.sort()

ans = 0
for i in range(N):
    x, h = XH[i]
    if h <= 0:
        continue

    XH[i][1] = 0
    c = math.ceil(h/A)
    ans += c

    dmg = A*c
    scp_end = x+D*2

    for j in range(i+1, N):
        xj, hj = XH[j]
        if xj <= scp_end:
            if hj > 0:
                XH[j][1] -= dmg
        else:
            break
    
# output
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, d, a = map(int, input().split())
xh = []
for _ in range(n):
    x, h = map(int, input().split())
    xh.append([x, h])

xh.sort(key=lambda x:x[0])
ind = 0
ans = 0
while ind<n:
    end = xh[ind][0]+2*d
    cnt = (xh[ind][1]+a-1)//a
    ans += cnt
    ind += 1
    i = ind
    while i<n and xh[i][0]<=end:
        xh[i][1] -= a*cnt
        i += 1
    while ind<n and xh[ind][1]<=0:
        ind += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, d, a = map(int, input().split())
xh = []
for _ in range(n):
    x, h = map(int, input().split())
    xh.append([x, h])

xh.sort(key=lambda x:x[0])
ind = 0
ans = 0
while ind<n:
    end = xh[ind][0]+2*d
    cnt = (xh[ind][1]+a-1)//a
    ans += cnt
    i = ind
    while i<n and xh[i][0]<=end:
        xh[i][1] = max(xh[i][1]-a*cnt, 0)
        i += 1
    while ind<n and xh[ind][1]==0:
        ind += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = [[0 for i in range(2)] for j in range(n)]
rang = [n]*(n-1)+[0]
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh.sort(key=lambda xh:xh[0])

for i in range(n):
    for j in range(rang[i-1],n):
        if xh[i][0]+d < xh[j][0]-d:
            rang[i] = j
            break

dam = [0]*n
for i in range(n):
    res = xh[i][1]-dam[i]
    pos = xh[i][0]
    if res > 0:
        nat = math.ceil(res/a)
        num += nat
        for j in range(i+1,rang[i]):
            dam[j] += a*nat

print(num)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = [[0 for i in range(2)] for j in range(n)]
rang = [0]*n
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh.sort(key=lambda xh:xh[0])

for i in range(n):
    for j in range(i+1,n):
        if xh[i][0]+d < xh[j][0]-d:
            rang[i] = j
            break
        elif j == n-1:
            rang[i] = n

dam = [0]*n
for i in range(n):
    res = xh[i][1]-dam[i]
    pos = xh[i][0]
    if res > 0:
        nat = math.ceil(res/a)
        num += nat
        for j in range(i+1,rang[i]):
            dam[j] += a*nat

print(num)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, d, a = map(int, input().strip().split())
  XsHs = [list(map(int, input().strip().split())) for _ in range(n)]
  XsHs.sort(key = lambda x:x[0])

  queue = list()
  total = 0
  ans = 0
  for x, h in XsHs:
    while True:
      if len(queue) != 0 and queue[0][0] < x:
        total -= queue[0][1]
        del queue[0]
      else:
        break
    h -= total
    if h > 0:
      num = (h+a-1)//a
      ans += num
      total += (num*a)
      queue.append((x+(2*d), num*a))
  print(ans)

if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh.sort(key=lambda xh:xh[0])
pos = 0
res = 0
nat = 0

dam = [0]*n
for i in range(n):
    res = xh[i][1]-dam[i]
    pos = xh[i][0]
    if res > 0:
        nat = math.ceil(res/a)
        num += nat
        for j in range(i+1,n):
            if xh[j][0]-d <= pos + d:
                dam[j] += a*nat
            else:
                break
print(num)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh.sort(key=lambda xh:xh[0])

dam = [0]*n
for i in range(n):
    res = xh[i][1]-dam[i]
    pos = xh[i][0]
    if res > 0:
        nat = math.ceil(res/a)
        num += nat
        for j in range(i+1,n):
            if xh[j][0]-d <= pos + d:
                dam[j] += a*nat
            else:
                break
print(num)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = []
for i in range(n):
    x,h = map(int,input().split())
    xh.append([x,h])

num = 0
xh.sort(key=lambda xh:xh[0])
l = len(xh)
dam = [0]*n
rang = [0]*n
for i in range(n):
    rang[i] = xh[i][0]-2*d

for i in range(n):
    res = xh[i][1]-dam[i]
    if res > 0:
        nat = math.ceil(res/a)
        pos = xh[i][0]
        num += nat
        for j in range(i+1,n):
            if rang[j] <= pos:
                dam[j] += a*nat
            else:
                break
print(num)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = []
for i in range(n):
    x,h = map(int,input().split())
    xh.append([x,h])

num = 0
xh.sort(key=lambda xh:xh[0])
l = len(xh)
dam = [0]*n
rang = [0]*n
for i in range(n):
    rang[i] = xh[i][0]-d
    
for i in range(n):
    res = xh[i][1]-dam[i]
    if res > 0:
        nat = math.ceil(res/a)
        pos = xh[i][0]+d
        num += nat
        for j in range(i+1,n):
            if rang[j] <= pos:
                dam[j] += a*nat
            else:
                break
print(num)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = []
for i in range(n):
    x,h = map(int,input().split())
    xh.append([x,h])

num = 0
xh.sort(key=lambda xh:xh[0])
l = len(xh)
dam = [0]*n
rang = [0]*n
for i in range(n):
    rang[i] = xh[i][0]-d

for i in range(n):
    res = xh[i][1]-dam[i]
    if res > 0:
        nat = math.ceil(res/a)
        pos = xh[i][0]+d
        num += nat
        for j in range(n):
            if rang[j] <= pos:
                dam[j] += a*nat
            else:
                break

print(num)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = []
for i in range(n):
    x,h = map(int,input().split())
    xh.append([x,h])

num = 0
xh.sort(key=lambda xh:xh[0])
l = len(xh)
dam = [0]*n
rang = []
for i in range(n):
    rang.append(xh[i][0] - d)

for i in range(n):
    res = xh[i][1]-dam[i]
    if res > 0:
        nat = math.ceil(res/a)
        pos = xh[i][0]+d
        num += nat
        for j in range(n):
            if rang[j] <= pos:
                dam[j] += a*nat

print(num)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = []
for i in range(n):
    x,h = map(int,input().split())
    xh.append([x,h])

num = 0
xh.sort(key=lambda xh:xh[0])
l = len(xh)
dam = [0]*n

for i in range(n):
    res = xh[i][1]-dam[i]
    if res > 0:
        nat = math.ceil(res/a)
        pos = xh[i][0]+d
        num += nat
        for j in range(n):
            if math.fabs(xh[j][0]-pos) <= d:
                dam[j] += a*nat

print(num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

n, d, a = map(int,input().split())
xh = np.zeros((n,2), dtype = int)
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh = xh[np.argsort(xh[:, 0])]

while xh.size > 0.5:
    nat = math.ceil((xh[0,1])/a)
    num += nat
    dam = nat*a
    side = xh[0,0]
    for i in range(xh.shape[0]):
        if xh[i,0] <= side+2*d:
            xh[i,1] -= dam
        else:
            break
    xh = xh[~np.any(xh<0.5,axis=1)]

print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
from operator import itemgetter

input = sys.stdin.readline


def main():
    N, D, A = [int(x) for x in input().split()]
    XH = [[None] for _ in range(N * 2)]
    X = [0] * (N * 2)
    for i in range(N):
        x, h = [int(x) for x in input().split()]
        XH[i * 2] = [x, h, float("inf")]
        XH[i * 2 + 1] = [x + 2 * D + 1, float("inf"), 0]
        X[i * 2] = x
        X[i * 2 + 1] = x + 2 * D + 1

    X.sort()
    XH.sort(key=itemgetter(0, 2))

    ans = 0
    ruiseki = 0

    for x, h, r in XH:
        if h != float("inf"):
            if h > ruiseki:
                tmpruiseki = -(-(h - ruiseki) // A) * A
                ans += -(-(h - ruiseki) // A)
                ruiseki += tmpruiseki
                nx = bisect.bisect_left(X, x + 2 * D + 1)
                if XH[nx][1] == float("inf"):
                    XH[nx][2] -= tmpruiseki
                else:
                    XH[nx + 1][2] -= tmpruiseki
            else:
                continue
        else:
            ruiseki += r

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
from operator import itemgetter

input = sys.stdin.readline


def main():
    N, D, A = [int(x) for x in input().split()]
    XH = []
    X = []
    for _ in range(N):
        x, h = [int(x) for x in input().split()]
        XH.append([x, h, float("inf")])
        XH.append([x + 2 * D + 1, float("inf"), 0])
        X.append(x)
        X.append(x + 2 * D + 1)

    X.sort()
    XH.sort(key=itemgetter(0, 2))

    ans = 0
    ruiseki = 0

    for x, h, r in XH:
        if h != float("inf"):
            if h > ruiseki:
                tmpruiseki = -(-(h - ruiseki) // A) * A
                ans += -(-(h - ruiseki) // A)
                ruiseki += tmpruiseki
                nx = bisect.bisect_left(X, x + 2 * D + 1)
                if XH[nx][1] == float("inf"):
                    XH[nx][2] -= tmpruiseki
                else:
                    XH[nx + 1][2] -= tmpruiseki
            else:
                continue
        else:
            ruiseki += r

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = []
for i in range(n):
    x,h = map(int,input().split())
    xh.append([x,h])

num = 0
xh.sort(key=lambda xh:xh[0])
x = []
h = []
for i in range(n):
    x.append(xh[i][0])
    h.append(xh[i][1])


while len(h) > 0.5:
    nat = math.ceil((h[0])/a)
    num += nat
    dam = nat*a
    for i in range(len(x)):
        if x[i] <= x[0]+2*d:
            h[i] -= dam
        else:
            break
    while len(h) > 0 and h[0] < 0.5:
        h.pop(0)
        x.pop(0)


print(num)

Submission status: Time Limit Exceeded

Solution code:
import math

n, d, a = map(int,input().split())
xh = []
for i in range(n):
    x,h = map(int,input().split())
    xh.append([x,h])

num = 0
xh.sort(key=lambda xh:xh[0])

while len(xh) > 0.5:
    nat = math.ceil((xh[0][1])/a)
    num += nat
    dam = nat*a
    for i in range(len(xh)):
        if xh[i][0] <= xh[0][0]+2*d:
            xh[i][1] -= dam
        else:
            break
    xh = [i for i in xh if i[1] > 0]

print(num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

n, d, a = map(int,input().split())
xh = np.zeros((n,2), dtype = int)
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh = xh[np.argsort(xh[:, 0])]

while xh.size > 0.5:
    nat = math.ceil((xh[0,1])/a)
    num += nat
    dam = nat*a
    for i in range(xh.shape[0]):
        if xh[i,0] <= xh[0,0]+2*d:
            xh[i,1] -= dam
        else:
            break
    xh = xh[~np.any(xh<0.5,axis=1)]

print(num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, d, a = map(int,input().split())
xh = np.zeros((n,2), dtype = int)
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh = xh[np.argsort(xh[:, 0])]

while xh.size > 0.5:
    if xh[0,1]%a == 0:
        nat = int((xh[0,1])/a)
    else:
        nat = int((xh[0,1])/a+1)
    num += nat
    dam = nat*a
    for i in range(xh.shape[0]):
        if xh[i,0] <= xh[0,0]+2*d:
            xh[i,1] -= dam
        else:
            break
    xh = xh[~np.any(xh<0.5,axis=1)]

print(num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n, d, a = map(int,input().split())
xh = np.zeros((n,2), dtype = int)
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh = xh[np.argsort(xh[:, 0])]

while xh.size > 0.5:
    if xh[0,1]%a == 0:
        nat = int((xh[0,1])/a)
    else:
        nat = int((xh[0,1])/a+1)
    num += nat
    dam = nat*a
    for i in range(xh.shape[0]):
        if xh[i,0] <= xh[0,0]+2*d:
            xh[i,1] -= dam
        else:
            break
    while xh[0,1] < 0.5:
        xh = np.delete(xh, 0, 0)
        if xh.size == 0:
            break
    if xh.size == 0:
        break

print(num)