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 C (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <stdio.h>

typedef long value_type;

value_type med3(value_type x, value_type y, value_type z) {
	if (x < y) {
		if (y < z) return y;
		else if (z < x) return x;
		else return z;
	} else {
		if (z < y) return y ;
		else if (x < z) return x;
		else return z;
	}
}

void quicksort(value_type a[], value_type b[], value_type left, value_type right) {
	value_type i, j, tmp, pivot;
	if (left < right) {
		i = left;
		j = right;
		pivot = med3(a[i], a[i + (j - i) / 2], a[j]);
		while (1) {
			while (a[i] < pivot) i++;
			while (pivot < a[j]) j--;
			if (i >= j) break;
			tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
			tmp = b[i];
			b[i] = b[j];
			b[j] = tmp;
			i++;
			j--;
		}
		quicksort(a, b, left, i - 1);
		quicksort(a, b, j + 1, right);
	}
}

value_type atkfront(value_type x[], value_type h[], value_type *p, value_type n, value_type d, value_type a) {
	value_type i, r, r2, ptr, dmg, num;
	r = x[*p] + 2 * d;
	for(i = *p + 1; i < n; i++) {
		if(x[i] > r) break;
	}
	r2 = i;
	num = ((long) h[*p] + a - 1) / a;
	dmg = num * a;
	ptr = r2;
	for(i = r2 - 1 ; i >= *p; i--) {
		h[i] = h[i] - dmg;
		if(h[i] > 0) ptr = i;
	}
	*p = ptr;
	return num;
}

int main(void) {
	value_type i, ptr, n;
	value_type d, a;
	value_type x[200000], h[200000];
	value_type num;

	scanf("%ld %ld %ld", &n, &d, &a);
	for(i = 0; i < n; i++) {
		scanf("%ld %ld", x+i, h+i);
	}
	quicksort(x, h, 0, n - 1);

	ptr = 0;
	num = 0;
	while(1) {
		num += atkfront(x, h, &ptr, n, d, a);
		if(ptr == n) break;
	}

	printf("%ld\n", num);

	return 0;
}