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++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int SIZE = (1 << 19) + 10;
vector<pii> vec;
vector<lint> unq;
struct SegmentTree {
	#define lson (root << 1)
	#define rson (root << 1 | 1)
	#define mid ((stdl + stdr) >> 1)
	lint val[SIZE], tag[SIZE];
	inline void build(int root = 1, int stdl = 0, int stdr = SZ(unq) - 1) {
		if (stdl == stdr) {
			val[root] = vec[stdl].sed;
			return;
		}
		build(lson, stdl, mid);
		build(rson, mid + 1, stdr);
		val[root] = max(val[lson], val[rson]);
	}
	inline void pushdown(int root) {
		if (tag[root]) {
			tag[lson] += tag[root];
			tag[rson] += tag[root];
			val[lson] -= tag[root];
			val[rson] -= tag[root];
			tag[root] = 0;
		}
	}
	inline pll query(int root = 1, int stdl = 0, int stdr = SZ(unq) - 1) {
		if (val[root] <= 0) return pll(- 1, - 1);
		if (stdl == stdr) return pll(stdl, val[root]);
		pushdown(root);
		return val[lson] > 0 ? query(lson, stdl, mid) : query(rson, mid + 1, stdr);
	}
	inline void modify(int l, int r, lint p, int root = 1, int stdl = 0, int stdr = SZ(unq) - 1) {
		if (l <= stdl && stdr <= r) {
			val[root] -= p;
			tag[root] += p;
			return;
		}
		pushdown(root);
		if (l <= mid) modify(l, r, p, lson, stdl, mid);
		if (r > mid) modify(l, r, p, rson, mid + 1, stdr);
		val[root] = max(val[lson], val[rson]);
	}
	#undef lson
	#undef rson
	#undef mid
}	tr;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, D, A;
	cin >> n >> D >> A;
	D <<= 1;
	rep (i, 1, n) {
		int x, y;
		cin >> x >> y;
		unq.emplace_back(x);
		vec.emplace_back(x, y);
	}
	sort(all(unq));
	sort(all(vec));
	tr.build();
	lint res = 0;
	auto getID = [&] (lint pos) {
		return upper_bound(all(unq), pos) - unq.begin() - 1;
	};
	while (true) {
		pll p = tr.query();
		if (p.fst == -1) break;
		lint tim = (p.sed + A - 1) / A ;res += tim;
		tr.modify(p.fst, getID(unq[p.fst] + D), tim * A);
	}
	cout << res << endl;
	return 0;
}