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 Kotlin (1.3.71) (judge verdict: Wrong Answer)

import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*

fun bsIdxLte(A: LongArray, X: Long, includeEqual:Boolean = false): Int {
    val N = A.size
    if (N == 0) return -1
    val xLess: (Long)->Boolean = if (includeEqual) {
        { Y:Long -> X < Y }
    } else {
        { Y:Long -> X <= Y }
    }
    if (xLess(A[0])) return -1
    var l = 0; var r = N
    while (l < r - 1) {
        val m = (l + r) / 2
        if (xLess(A[m])) {
            r = m
        } else {
            l = m
        }
    }
    return l
}
fun bsIdxGte(A: LongArray, X: Long, includeEqual:Boolean = false): Int {
    val N = A.size
    if (N == 0) return N
    val xGreater: (Long)->Boolean = if (includeEqual) {
        { Y:Long -> X > Y }
    } else {
        { Y:Long -> X >= Y }
    }
    if (xGreater(A[N-1])) return N
    val xLess: (Long)->Boolean = if (includeEqual) {
        { Y:Long -> X <= Y }
    } else {
        { Y:Long -> X < Y }
    }
    var l = -1; var r = N - 1
    while (l + 1 < r) {
        val m = (l + r) / 2
        if (xLess(A[m])) {
            r = m
        } else {
            l = m
        }
    }
    return r
}
data class IntLongPair(val first: Int, val second: Long)
class SegTreeSumP(val P: ArrayList<IntLongPair>) {
    private var sg = LongArray(0)
    private var sg2 = LongArray(0)
    private var pos = LongArray(P.size+1){LINF}
    var size = 0
        private set
    init {
        val N = P.size
        //P.sortBy { it.first }

        for (i in 0 until N) {
            pos[i] = P[i].first.toLong()
        }
        var sz = 1
        while (sz < N) {
            sz = sz shl 1
        }
        this.size = sz
        sg = LongArray(sz shl 1){0}
        sg2 = LongArray(sz shl 1){0}
    }

    private fun add(i: Int, j: Int, X: Long, v: Int = 0, l: Int = 0, r:Int = this.size) {
        if (r <= i || j <= l) {
            return
        }
        if (i <= l && r <= j) {
            this.sg2[v] += X
        } else {
            sg[v] += (min(j, r) - max(i, l)) * X
            val m = (l + r) / 2
            add(i, j, X, v * 2 + 1, l, m)
            add(i, j, X, v * 2 + 2, m, r)
        }
    }
    fun addPos(ix: Int, jx: Int, X: Long) {
        val i = bsIdxLte(pos, ix.toLong(), true)
        val j = bsIdxGte(pos, jx.toLong(), true)
        this.add(i,j,X)
    }

    private fun add(i: Int, X: Long) {
        add(i, i+1, X)
    }

    fun addPos(ix: Int, X: Long) {
        val i = bsIdxLte(pos, ix.toLong(), true)
        this.add(i, X)
    }

    private fun sum(i: Int, j: Int, v: Int = 0, l: Int = 0, r: Int = this.size): Long {
        if (r <= i || j <= l) {
            return 0L
        } else if (i <= l && r <= j) {
            return sg[v] + (r - l) * sg2[v]
        } else {
            val base = (min(j, r) - max(i, l)) * sg2[v]
            val m = (l + r) / 2
            val vl = sum(i, j, 2 * v + 1, l, m)
            val vr = sum(i, j, 2 * v + 2, m, r)
            return base + vl + vr
        }
    }
    fun sumPos(ix: Int, jx: Int): Long {
        val i = bsIdxLte(pos, ix.toLong(), true)
        val j = bsIdxGte(pos, jx.toLong(), true)
        return this.sum(i, j)
    }

    fun getPos(ix: Int): Long {
        val i = bsIdxLte(pos, ix.toLong(), true)
        return this.sum(i, i+1)
    }
}

fun greedy(XH: ArrayList<IntLongPair>, D: Int, A: Long): Long {
    val N = XH.size
    val sgt = SegTreeSumP(XH)
    for (i in 0 until N) {
        val (x, h) = XH[i]
        sgt.addPos(x, h)
    }

    var cnt = 0L
    for (i in 0 until N) {
        val x = XH[i].first
        val h = sgt.getPos(x)

        if (h <= 0) continue
        val ct = (h+A-1)/A
        val xr = min(x+2*D, 1e9.toInt())
        sgt.addPos(x, xr + 1, -A*ct)

        cnt += ct
    }

    return cnt
}


fun solve() {
    val (N, D, A) = rd.readIntArray()
    val XH = ArrayList<IntLongPair>(N)
    for (i in 0 until N) {
        val (x, h) = rd.readIntArray()
        XH.add(IntLongPair(x,h.toLong()))
    }
    XH.sortBy { it.first }

    val ans = greedy(XH, D, A.toLong())

    println(ans)
}


//val rd = debug.Reader("abc", "153", "f", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long, val col: Int)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}