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 Go (1.6) (judge verdict: Runtime Error)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// Data :
type Data struct {
	X int
	H int
}

// Datas :
type Datas []Data

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	return p[i].X < p[j].X
}

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// Merge : ソート済みの配列をマージする
func Merge(a, b []Data) []Data {
	result := make([]Data, len(a)+len(b))

	var i, j, cnt int
	for i+j < len(a)+len(b) {
		if a[i].X < b[j].X {
			result[cnt] = a[i]
			i++
		} else {
			result[cnt] = b[j]
			j++
		}
		cnt++

		if i == len(a) {
			for j < len(b) {
				result[cnt] = b[j]
				cnt++
				j++
			}
			break
		}

		if j == len(b) {
			for i < len(a) {
				result[cnt] = a[i]
				cnt++
				i++
			}
			break
		}
	}

	return result
}

// DivideArray :
func DivideArray(a []Data) ([]Data, []Data) {
	return a[:len(a)/2], a[len(a)/2:]
}

// MergeSort :
func MergeSort(a []Data) []Data {
	a1, a2 := DivideArray(a)

	if len(a1) > 1 {
		a1 = MergeSort(a1)
	}
	if len(a2) > 1 {
		a2 = MergeSort(a2)
	}
	a = Merge(a1, a2)
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	D := getInt()
	A := getInt()
	m := make(Datas, N)
	for i := 0; i < N; i++ {
		m[i].X = getInt()
		m[i].H = getInt()
	}

	//	sort.Sort(m)
	m = MergeSort(m)

	ans := 0
	D = 2 * D
	for i := 0; i < N; i++ {
		if m[i].H <= 0 {
			continue
		}
		pos := m[i].X + D
		x := m[i].H / A
		if m[i].H%A != 0 {
			x++
		}
		ans += x
		x = x * A
		for j := i; j < N; j++ {
			if m[j].X > pos {
				break
			} else {
				m[j].H -= x
			}
		}
	}
	fmt.Println(ans)
}