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 Python (3.4.3) (judge verdict: Wrong Answer)

import bisect
import operator


import operator


class SegmentTree():

    def __init__(self, size, op=min, init_value=10**8):
        """初期化"""
        self.size = size
        self.op = op
        self.init_value = init_value
        n = 2 ** ((size-1).bit_length())
        treesize = n * 2
        self.st = [init_value for i in range(treesize)]
        # 遅延評価用の更新値キャッシュ
        self.is_dirty = [False for i in range(treesize)]
        self.uv = [0 for i in range(treesize)]
    
    @classmethod
    def from_array(cls, a, op=min, init_value=10**8):
        st = cls(len(a), op=op, init_value=init_value)
        for i, x in enumerate(a):
            st.update(i, i+1, x)
        return st
    
    def _lazy_eval(self, k):
        """ノードの遅延評価"""
        if not self.is_dirty[k]:
            return
        n = len(self.st) // 2
        if k < n:
            self.uv[k * 2] = self.uv[k]
            self.is_dirty[k * 2] = True
            self.uv[k * 2 + 1] = self.uv[k]
            self.is_dirty[k * 2 + 1] = True
        self.st[k] = self.uv[k]
        self.uv[k] = 0
        self.is_dirty[k] = False
    
    def _update(self, a, b, value, k, l, r):
        """区間[a, b) に対する値の更新
        k: 着目しているノード (1-indexed)
        l: 探索区間 st[l, r) の左端 (0-indexed)
        r: 探索区間 st[l, r) の右端 (0-indexed)
        """
        self._lazy_eval(k)
        if r <= a or b <= l:
            return
        if a <= l and r <= b:
            self.uv[k] = value
            self.is_dirty[k] = True
            self._lazy_eval(k)
            return
        mid = (l + r) // 2
        self._update(a, b, value, k * 2, l, mid)
        self._update(a, b, value, k * 2 + 1, mid, r)
        self.st[k] = self.op(self.st[k * 2], self.st[k * 2 + 1])
    
    def update(self, a, b, value):
        """区間[a, b) に対する値の更新"""
        if a > b:
            raise ValueError("a must be less than equal b.")
        n = len(self.st) // 2
        return self._update(a, b, value, k=1, l=0, r=n)
    
    def _add(self, a, b, value, k, l, r):
        """区間[a, b) に対する加算
        k: 着目しているノード (1-indexed)
        l: 探索区間 st[l, r) の左端 (0-indexed)
        r: 探索区間 st[l, r) の右端 (0-indexed)
        """
        self._lazy_eval(k)
        if r <= a or b <= l:
            return
        if a <= l and r <= b:
            self.uv[k] = self.st[k] + value
            self.is_dirty[k] = True
            self._lazy_eval(k)
            return
        mid = (l + r) // 2
        self._update(a, b, value, k * 2, l, mid)
        self._update(a, b, value, k * 2 + 1, mid, r)
        self.st[k] = self.op(self.st[k * 2], self.st[k * 2 + 1])

    def add(self, a, b, value):
        """区間[a, b) に対する加算"""
        if a > b:
            raise ValueError("a must be less than equal b.")
        n = len(self.st) // 2
        return self._add(a, b, value, k=1, l=0, r=n)
    
    def _query(self, a, b, k, l, r):
        """区間[a, b) に対する累積操作
        k: 着目しているノード (1-indexed)
        l: 探索区間 st[l, r) の左端 (0-indexed)
        r: 探索区間 st[l, r) の右端 (0-indexed)
        """
        self._lazy_eval(k)
        if r <= a or b <= l:
            return self.init_value
        if a <= l and r <= b:
            return self.st[k]
        mid = (l + r) // 2
        lv = self._query(a, b, k * 2, l, mid)
        rv = self._query(a, b, k * 2 + 1, mid, r)
        return self.op(lv, rv)

    def query(self, a, b):
        """区間[a, b) に対する累積操作"""
        if a > b:
            raise ValueError("a must be less than equal b.")
        n = len(self.st) // 2
        return self._query(a, b, k=1, l=0, r=n)


def read():
    N, D, A = list(map(int, input().strip().split()))
    XH = list()
    for i in range(N):
        x, h = list(map(int, input().strip().split()))
        XH.append((x, h))
    return N, D, A, XH


def solve(N, D, A, XH):
    XH = sorted(XH)
    X = [x for x, h in XH]
    H = [h for x, h in XH]

    st = SegmentTree(N)
    for i, (x, h) in enumerate(XH):
        st.update(i, i+1, h)

    ans = 0
    i = 0
    while i < N:
        l = XH[i][0]
        r = l + 2 * D + 1
        c = XH[i][1] // A + (XH[i][1] % A > 0)
        v = c * A
        lidx = bisect.bisect_left(X, l)
        ridx = bisect.bisect_left(X, r)
        st.add(lidx, ridx, -v)
        ans += c
        m = -1
        i += 1
        while i < N:
            m = st.query(i, i+1)
            if m > 0:
                break
            i += 1
    return ans


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))