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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class Data
{
	public long X;
	public long H;

	public Data(long x, long h)
	{
		X = x;
		H = h;
	}
}

public class F
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		long D = GetLong();
		long A = GetLong();
		long[] X = new long[N];
		long[] H = new long[N];
		for(int i = 0; i < N; i++)
		{
			X[i] = GetLong();
			H[i] = GetLong();
		}
		var list = new List<Data>();
		for(int i = 0; i < N; i++)
			list.Add(new Data(X[i], H[i]));

		list.Sort((x, y) => x.X.CompareTo(y.X));

		var lst = new LazySegmentTree(N);
		for(int i = 0; i < N; i++)
			lst.RangeUpdate(i, i + 1, list[i].H);

		long ans = 0;
		for(int i = 0; i < N; i++)
		{
			var rest = lst.Query(i, i + 1);
			if(rest <= 0)
				continue;

			long cnt = (rest + A - 1) / A;
			int to = binarySearch(N, list, list[i].X + 2 * D);
			lst.RangeUpdate(i, to + 1, - cnt * A);
			ans += cnt;
		}
		WriteLine(ans);
	}

	private int binarySearch(int N, List<Data> list, long key)
	{
		int ok = -1;
		int ng = N;
		while(Abs(ok - ng) > 1)
		{
			int mid = (ok + ng) / 2;
			if(list[mid].X <= key)
				ok = mid;
			else
				ng = mid;
		}
		return ok;
	}
}

public class LazySegmentTree
{
	private int N;
	private long[] dat;
	private long[] lazy;

	public LazySegmentTree(int n)
	{
		N = 1;		
		while(N < n)
			N <<= 1;
			
		dat = new long[2 * N - 1];
		for(int i = 0; i < 2 * N - 1; i++)
			dat[i] = 0;

		lazy = new long[2 * N - 1];
	}

	private void eval(int k, int l, int r)
	{
		if(lazy[k] == 0)
			return;

		dat[k] += lazy[k];

		// propagate to children
		if(r - l > 1)
		{
			lazy[2 * k + 1] += lazy[k] / 2;
			lazy[2 * k + 2] += lazy[k] / 2;
		}
		
		lazy[k] = 0;
	}

	public void RangeUpdate(int a, int b, long x, int k = 0, int l = 0, int r = -1)
	{
		if(r == -1)
			r = N;

		// evaluate propagation from parent
		eval(k, l, r);

		if(b <= l || r <= a)
			return;

		if(a <= l && r <= b)
		{
			// update
			lazy[k] += (long)(r - l) * x;
			eval(k, l, r);
		}
		else
		{
			RangeUpdate(a, b, x, 2 * k + 1, l, (l + r) / 2);
			RangeUpdate(a, b, x, 2 * k + 2, (l + r) / 2, r);
			dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
		}
	}

	public long Query(int a, int b, int k = 0, int l = 0, int r = -1)
	{
		if(r == -1)
			r = N;

		if(r <= a || b <= l)
			return 0;

		eval(k, l, r);

		if(a <= l && r <= b)
			return dat[k];
		else
		{
			long vl = Query(a, b, k * 2 + 1, l, (l + r) / 2);
			long vr = Query(a, b, k * 2 + 2, (l + r) / 2, r);
			return vl + vr;
		}
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}