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:
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, D, A = lr()
XH = [lr() for _ in range(N)]
XH.sort(key=lambda x:x[0])

over = [N] * (N+1) # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値（最大はNで対象なし）
cur = 1
for i in range(N):
    while cur < N and XH[i][0] + D + D >= XH[cur][0]:
        cur += 1
    over[i] = cur

damage = 0 # 今までの累計のダメージ数　(影響のないダメージは引く)
reset = [0] * (N+1) # 対象のモンスターの影響しなかったダメージ
answer = 0
for i in range(N):
    x, h = XH[i]
    damage -= reset[i]
    h = h - damage
    time = (h+A-1)//A
    answer += time
    damage += A * time
    reset[over[i]] += A * time

print(answer)
# 00

Submission status: Wrong Answer

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, D, A = lr()
XH = [lr() for _ in range(N)]
XH.sort(key=lambda x:x[0])

over = [N] * (N+1) # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値（最大はNで対象なし）
cur = 1
for i in range(N):
    while cur < N and XH[i][0] + D + D >= XH[cur][0]:
        cur += 1
    over[i] = cur

damage = 0 # 今までの累計のダメージ数　(影響のないダメージは引く)
reset = [0] * (N+1) # 対象のモンスターの影響しなかったダメージ
answer = 0
for i in range(N):
    x, h = XH[i]
    damage -= reset[i]
    h = h - damage
    time = (h+A-1)//A
    answer += time
    damage += A * time
    reset[over[i]] += A * time

print(answer)
# 00

Submission status: Wrong Answer

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, D, A = lr()
XH = [lr() for _ in range(N)]
XH.sort(key=lambda x:x[0])

over = [N] * (N+1) # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値（最大はNで対象なし）
cur = 1
for i in range(N):
    while cur < N and XH[i][0] + D + D >= XH[cur][0]:
        cur += 1
    over[i] = cur

damage = 0 # 今までの累計のダメージ数
reset = [0] * (N+1) # 対象のモンスターの影響しなかったダメージ
answer = 0
for i in range(N):
    x, h = XH[i]
    h = h - damage + reset[i]
    time = (h+A-1)//A
    answer += time
    damage += A * time
    reset[over[i]] += A * time
    reset[i+1] += reset[i] # resetは累計

print(answer)
# 00

Submission status: Wrong Answer

Solution code:
from math import ceil
from bisect import bisect_right
n,d,a=map(int,input().split())
lis=[list(map(int,input().split())) for i in range(n)]
x=[]
lis.sort()
for i in range(n):
  x.append(lis[i][0])
ran,ans,cnt=2*d,0,0
s=[0]*(n+1)
for i in range(n):
  r=lis[i][0]+ran
  inde=bisect_right(x,r)
  if inde!=i+1:
    if ceil(lis[i][1]/a)>cnt:
      s[inde]-=ceil(lis[i][1]/a)-cnt
      s[i]+=ceil(lis[i][1]/a)-cnt
      cnt=ceil(lis[i][1]/a)
  else:
    if ceil(lis[i][1]/a)>cnt:
      s[i]+=ceil(lis[i][1]/a)-cnt
      cnt=0
for i in range(n-1):
  s[i+1]+=s[i]
print(max(s))

Submission status: Wrong Answer

Solution code:
from math import ceil
from bisect import bisect_right
n,d,a=map(int,input().split())
lis=[list(map(int,input().split())) for i in range(n)]
x=[]
lis.sort()
for i in range(n):
  x.append(lis[i][0])
ran,ans,cnt=2*d,0,0
s=[0]*(n+1)
for i in range(n):
  r=lis[i][0]+ran
  inde=bisect_right(x,r)
  if inde!=i+1:
    if ceil(lis[i][1]/a)>cnt:
      s[inde]-=ceil(lis[i][1]/a)-cnt
      s[i]+=ceil(lis[i][1]/a)-cnt
      cnt=ceil(lis[i][1]/a)
  else:
    if ceil(lis[i][1]/a)>cnt:
      s[i]+=ceil(lis[i][1]/a)-cnt
      cnt=0
print(s)
for i in range(n-1):
  s[i+1]+=s[i]
print(max(s))

Submission status: Wrong Answer

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, D, A = lr()
XH = [lr() for _ in range(N)]
XH.sort(key=lambda x:x[0])

over = [N] * (N+1) # over[i]はi番目のモンスターを攻撃した時影響のないモンスターの最小値（最大はNで対象なし）
cur = 1
for i in range(N):
    while cur < N and XH[i][0] + D + D >= XH[cur][0]:
        cur += 1
    over[i] = cur

damage = 0 # 今までの累計のダメージ数
reset = [0] * (N+1) # 対象のモンスターの影響しなかったダメージ
answer = 0
for i in range(N):
    x, h = XH[i]
    h = h - damage + reset[i]
    time = (h+A-1)//A
    answer += time
    damage += A * time
    reset[over[i]] = A * time
    reset[i+1] += reset[i] # resetは累計

print(answer)
# 00

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N,D,A = map(int,input().split())
X = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
B = [0 for _ in range(N+1)]
cnt = 0
cur = 0
delta = 0
flag = 0
while cur<N:
    x = X[cur][0]
    h = X[cur][1]+delta
    if h%A==0:
        n = h//A
    else:
        n = h//A+1
    ind = bisect_right(X,[x+2*D,10**9+1])
    B[cur] += -n*A
    B[ind] += n*A
    cnt += n
    flag = 0
    for i in range(cur,N):
        delta += B[i]
        if X[i][1]+delta>0:
            cur = i
            flag = 1
            break
    if flag==0:
        cur = N
print(cnt)