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.

Solution in Lua (Lua 5.3.5) (judge verdict: Wrong Answer)

local function meld(a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

local function pair(a)
    local b=a and a[4]
    if not b then
        return a
    end
    local q={}
    while b do
        local c=b[4]
        a[4]=false
        b[4]=false
        table.insert(q,meld(a,b))
        a=c
        b=a and a[4]
    end
    for i=#q,1,-1 do
        a=meld(a,q[i])
    end
    return a
end


local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,k,v)
	if not self[1] then
		self[1]={
            k,
            v,
            false,
            false,
		}
	else
		if self[1][1]<k then
			self[1][3]={
				k,
				v,
				false,
				self[1][3],
			}
		else
			self[1]={
				k,
				v,
				self[1],
				false,
			}
		end
	end
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=pair(self[1][3])
end

PairingHeap.join=function(self,other)
	if self[1][1]<other[1][1]then
		other[1][4]=self[1][3]
        self[1][3]=other[1]
	else
		self[1][4]=other[1][3]
        other[1][3]=self[1]
        self[1]=other[1]
    end
    return self
end

PairingHeap.new=function(self)
    local obj={}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------

local n,d,a=io.read("n","n","n")
local pq=PairingHeap:new()
for i=1,n do
    local x,h=io.read("n","n")
    pq:push(x,{x,h,true})
end

local atack=0
local total=0
while not pq:empty() do
    local x,h,c=table.unpack(pq:top())
    pq:pop()
    if c then
        if atack*a<h then
            h=h-atack*a
            local count=(h-1)//a+1
            pq:push(x+2*d,{x+2*d,count,false})
            total=total+count
            atack=atack+count
        end
    else
        atack=atack-h
    end
end
print(total)