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# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (N, D, A) = ReadStream<int,long,long>();
        var X = new long[N];
        var H = new long[N];
        for (int i = 0; i < N; i++)
        {
            var xh = RLongs();
            X[i] = xh[0];
            H[i] = xh[1];
        }
        Array.Sort(X,H);
        var segtree = new LazySegment(H);
        long count = 0;
        for (int i = 0; i < N; i++)
        {
            var h = segtree.Sum(i, i + 1);
            if (h== 0) continue;
            long c = h / A;
            if (h % A != 0) c++;

            var (lb, ub) = (-1, N);
            while (ub - lb > 1)
            {
                var mid = (lb + ub) / 2;
                if (X[mid]<X[i]+2*D+1) lb = mid;
                else ub = mid;
            }
            segtree.Add(i, ub, -A * c);
            count += c;
        }
        WriteLine(count);
    }
}
class LazySegment
{
    int n;
    long[] Data, Lazy;

    public LazySegment(long[] v)
    {
        int N = v.Length;
        n = 1; while (n < N) n *= 2;
        Data = new long[n * 2 - 1];
        Lazy = new long[n * 2 - 1];
        for (int i = 0; i < N; i++)
        {
            Data[i + n - 1] = v[i];
        }
        for (int i = n - 2; i >= 0; i--)//二段目n-1から(一段目は2n-1)
        {
            Data[i] = Data[i * 2 + 1] + Data[i * 2 + 2];
        }
    }
    void eval(int k, int l, int r)//nodeが呼び出された時に伝達する。
    {
        if (Lazy[k] != 0)
        {
            Data[k] = Max(0,Data[k]+ Lazy[k]);
            if (r - l > 1)
            {
                Lazy[k * 2 + 1] += Lazy[k] / 2;
                Lazy[k * 2 + 2] += Lazy[k] / 2;
            }
        }
        Lazy[k] = 0;
    }
    public void Add(int a, int b, long x) => Add(a, b, x, 0, 0, n);
    public void Add(int a, int b, long x, int k, int l, int r)
    {
        eval(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b)//完全にl,rが含まれる
        {
            Lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else//どっちか片方範囲外
        {
            Add(a, b, x, k * 2 + 1, l, (l + r) / 2);
            Add(a, b, x, k * 2 + 2, (l + r) / 2, r);
            Data[k] = Max(0,Data[k * 2 + 1] + Data[k * 2 + 1]);
        }
    }
    public long Sum(int a, int b) => Sum(a, b, 0, 0, n);
    private long Sum(int a, int b, int k, int l, int r)
    {
        if (b <= l || r <= a) return 0;
        eval(k, l, r);
        if (a <= l && r <= b) return Data[k];
        else
        {
            var vl = Sum(a, b, k * 2 + 1, l, (l + r) / 2);
            var vr = Sum(a, b, k * 2 + 2, (l + r) / 2, r);
            return vl + vr;
        }
    }
}
class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}