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: Wrong Answer

Solution code:
from collections import defaultdict, Counter, namedtuple, deque
from bisect import bisect_left
from functools import reduce
import math

MOD = 1000000007
INF = float("inf")

n, d, a = map(int, input().split())

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

monsters.sort()

attack = 0
que = deque()
attack_num = 0

for monster in monsters:
    xx, hh = monster
    while que and que[0][0] < xx-d:
        attack -= que[0][1]
        que.popleft()

    # print("a", x, h, attack, que)

    if hh-attack <= 0:
        continue

    a_times = (hh-attack-1)//a + 1
    a_coor = xx + d
    attack_num += a_times
    attack += a_times*a
    que.append((a_coor, attack))

    # print("b", attack_num, que)

print(attack_num)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter, namedtuple, deque
from bisect import bisect_left
from functools import reduce
import math

MOD = 1000000007
INF = float("inf")

n, d, a = map(int, input().split())

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

monsters.sort()

attack = 0
que = deque()
attack_num = 0

for monster in monsters:
    x, h = monster
    while que and que[0][0] < x-d:
        attack -= que[0][1]
        que.popleft()

    # print("a", x, h, attack, que)

    if h-attack <= 0:
        continue

    a_times = (h-attack-1)//a + 1
    a_coor = monster[0] + d
    attack_num += a_times
    attack += a_times*a
    que.append((a_coor, attack))

    # print("b", attack_num, que)

print(attack_num)

Submission status: Wrong Answer

Solution code:
#input
N, D, A = map(int, input().split())
X = [0]*N
H = [0]*N
for i in range(N):
    X[i], H[i] = map(int, input().split())

#output
import numpy as np
import bisect as bi

X = np.array(X)
H = np.array(H)
idx = np.argsort(X)
X = X[idx]
H = H[idx]

damage = np.zeros(N, int)
answer = 0

for i in range(N):
    if H[i] <= 0:
        continue
    else:
        J = (H[i]-1+A)//A
        damage[i] = J*A
        a = bi.bisect_right(X, X[i]+2*D)
        if a <= N-1:
            damage[a] = -J*A
    damage = np.cumsum(damage)
    answer += J
    H -= damage
    damage = np.cumsum(damage) - damage[i]

print(answer)

Submission status: Wrong Answer

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: Wrong Answer

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: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
N, D, A = map(int, input().split())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
L.sort(key=lambda x: x[0])
# print(*L)
ans = 0
cnt = 0
for i in range(N):
    x, h = L[i]
    if i == 0:
        past_damage = ceil(h / A) * A
        past_point = x
        ans += past_damage // A
        cnt += past_damage
    else:
        if x <= past_point + 2 * D:
            if past_damage < ceil(h / A) * A:
                ans += ceil((ceil(h/A) * A - past_damage) / A)
                # past_damage = ceil(h / A) * A
                past_point = x
        else:
            # continue
            cnt = 0
            past_damage = ceil(h / A) * A
            past_point = x
            ans += past_damage // A
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
N, D, A = map(int, input().split())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
L.sort(key=lambda x: x[0])
# print(*L)
ans = 0
cnt = 0
for i in range(N):
    x, h = L[i]
    if i == 0:
        past_damage = ceil(h / A) * A
        past_point = x
        ans += past_damage // A
        cnt += past_damage
    else:
        if x <= past_point + 2 * D:
            if past_damage < ceil(h / A) * A:
                ans += ((ceil(h/A) * A - past_damage) / A)
                past_damage = ceil(h / A) * A
                past_point = x
        else:
            # continue
            cnt = 0
            past_damage = ceil(h / A) * A
            past_point = x
            ans += past_damage // A
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil
N, D, A = map(int, input().split())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
L.sort(key=lambda x: x[0])
# print(*L)
ans = 0
cnt = 0
for i in range(N):
    x, h = L[i]
    if i == 0:
        past_damage = ceil(h / A) * A
        past_point = x
        ans += past_damage // A
        cnt += past_damage
    else:
        if x <= past_point + 2 * D:
            if past_damage < ceil(h / A) * A:
                ans += ceil((ceil(h/A) * A - past_damage) / A)
                past_damage = ceil(h / A) * A
                past_point = x
        else:
            # continue
            cnt = 0
            past_damage = ceil(h / A) * A
            past_point = x
            ans += past_damage // A
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

ans = 0
cnt = 0
que = deque()
for x, h in XH:
    while que and que[0][0] <= x:
        cnt -= que.popleft()[1]
    h -= cnt * A

    ness = -(-h // A)
    cnt += ness
    ans += ness
    que.append((x + 2 * D + 1, ness))
print(ans)

Submission status: Wrong Answer

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
        
        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: Wrong Answer

Solution code:
from collections import deque

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

# process
XH.sort()
print(XH)

ans = 0
dq = deque()
dam = 0
for x, h in XH:
    while dq:
        x2, h2 = dq[0]
        if x > x2:
            dam -= h2
            dq.popleft()
        else:
            break

    h -= dam
    if h <= 0:
        continue

    c = -(-h//A)
    ans += c
    d = A*c
    dam += d
    dq.append((x+D*2, d))
    
# output
print(ans)

Submission status: Wrong Answer

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 = q.dequeue()
        qs = []
        while tmp != None:
            hanni_q,dame_q = tmp
            if X < hanni_q:
                H -= dame_q
                qs.append((hanni_q,dame_q))
            tmp = q.dequeue()
            
        for j in qs:
            q.enqueue(j)
        
        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
    
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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 = q.dequeue()
        qs = []
        while tmp != None:
            hanni_q,dame_q = tmp
            if X <= hanni_q:
                H -= dame_q
                qs.append((hanni_q,dame_q))
            tmp = q.dequeue()
            
        for j in qs:
            q.enqueue(j)
        
        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
    
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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 = []
    R = [0] * (N * 2)
    for _ in range(N):
        x, h = [int(x) for x in input().split()]
        XH.append([x, h])
        XH.append([x + 2 * D + 1, float("inf")])
        X.append(x)
        X.append(x + 2 * D + 1)

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

    ans = 0
    ruiseki = 0

    for i in range(N * 2):
        x, h = XH[i]
        r = R[i]
        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"):
                    R[nx] -= tmpruiseki
                else:
                    R[nx + 1] -= tmpruiseki
            else:
                continue
        else:
            ruiseki += r

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,d,a = map(int,input().split())
monsters = [tuple(map(int,input().split())) for _ in range(n)]
monsters.sort()

# 各モンスターを倒すためにおこなった攻撃回数を記録する
# atk_count[1]が2の場合、x2番目のモンスターに対して2回攻撃をおこなったことを意味する
atk_count = [0]*n
atk_count_sum = 0
l = 0 # 左端
for i in range(n):
    x = monsters[i][0]
    h = monsters[i][1]
    # 尺取り法
    while monsters[l][0] + 2*d < x:
        atk_count_sum -= atk_count[l]
        l += 1
    # 既に受けているダメージ
    al = atk_count_sum * a
    if h > 0:
        atk_count[i] = -(-(h-al)//a)
    atk_count_sum += atk_count[i]
print(sum(atk_count))

Submission status: Wrong Answer

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
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
print(rang)

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: Wrong Answer

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(rang[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: Wrong Answer

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] = min([j+1,n])
            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: Wrong Answer

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 for i in range(n)]
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]
    rang[i] = x
print(xh,rang)

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 rang[j]-d <= pos + d:
                dam[j] += a*nat
            else:
                break
print(num)

Submission status: Wrong Answer

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 for i in range(n)]
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]
    rang[i] = x

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 rang[j] <= pos + 2*d:
                dam[j] += a*nat
            else:
                break
print(num)

Submission status: Wrong Answer

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]
    rang[i] = x-2*d

num = 0
xh.sort(key=lambda xh:xh[0])
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]
        num += nat
        for j in range(i+1,n):
            if rang[j] <= pos:
                dam[j] += a*nat
            else:
                break
print(num)

Submission status: Wrong Answer

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
                print(j,dam[j])
            else:
                break
print(num)

Submission status: Wrong Answer

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: Wrong Answer

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]

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: Wrong Answer

Solution code:
from operator import itemgetter
import bisect
import math

N,d,a = map(int, input().split())
xh = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
x = []
for X,h in xh:
  x.append(X)
ans = 0
attack_start = [i for i in range(N)]
now = 0
cumsum = [0] * (N+1)
for L,(X,H) in enumerate(xh):
  R = bisect.bisect_right(x,X+2*d)
  for i in range(now,R):
    attack_start[i] = L
  now = R
  damage = (cumsum[L] - cumsum[attack_start[L]]) * a
  attack_time = max(0,math.ceil((H - damage) / a))
  ans += attack_time
  cumsum[L+1] = ans
print(ans)  
print(attack_start)
print(cumsum)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
from operator import itemgetter
import bisect
import math

N,d,a = map(int, input().split())
xh = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
x = []
for X,h in xh:
  x.append(X)
ans = 0
attack_start = [i for i in range(N)]
now = 0
cumsum = [0] * (N+1)
for L,(X,H) in enumerate(xh):
  R = bisect.bisect_right(x,X+2*d)
  for i in range(now,R):
    attack_start[i] = L
  now = R
  damage = (cumsum[L] - cumsum[attack_start[L]]) * a
  attack_time = math.ceil((H - damage) / a) 
  ans += attack_time
  cumsum[L+1] = ans
print(ans)

Submission status: Wrong Answer

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: Wrong Answer

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:
    if len(queue) != 0 and queue[0][0] < x:
      total -= queue[0][1]
      del queue[0]
    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: Wrong Answer

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))

    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
                elif XH[nx + 1][1] == float("inf"):
                    XH[nx + 1][2] -= tmpruiseki
                else:
                    XH[nx + 2][2] -= tmpruiseki
            else:
                continue
        else:
            ruiseki += r

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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))

    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: Wrong Answer

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, 0]
        XH[i * 2 + 1] = [x + 2 * D + 1, 0, 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 != 0:
            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] == 0:
                    XH[nx][2] -= tmpruiseki
                else:
                    XH[nx + 1][2] -= tmpruiseki
            else:
                continue
        else:
            ruiseki += r

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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, 0]
        XH[i * 2 + 1] = [x + 2 * D + 1, 0, 0]
        X[i * 2] = x
        X[i * 2 + 1] = x + 2 * D + 1

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

    ans = 0
    ruiseki = 0

    for x, h, r in XH:
        if h != 0:
            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] == 0:
                    XH[nx][2] -= tmpruiseki
                else:
                    XH[nx + 1][2] -= tmpruiseki
            else:
                continue
        else:
            ruiseki += r

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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, 0]
        XH[i * 2 + 1] = [x + 2 * D + 1, 0, 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 != 0:
            if h > ruiseki:
                tmpruiseki = -(-(h - ruiseki) // A) * A
                ans += -(-(h - ruiseki) // A)
                ruiseki += tmpruiseki
                nx = bisect.bisect_left(X, x + 2 * D + 1)
                XH[nx][2] -= tmpruiseki
            else:
                continue
        else:
            ruiseki += r

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 = []

'''
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)