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 Rust (1.42.0) (judge verdict: Accepted)

#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    そう甘くはないんだな〜w
*/

// from std...
use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, multinomial, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, Num, NumAssignOps, NumOps, One, Pow, Zero};
use permutohedron::Heap;
use proconio::{
    fastout, input, is_stdin_empty,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use rand::random;

pub const MOD10E9_7: usize = 1000000007;
pub const MOD99_: usize = 998244353;
pub const MAX: usize = std::usize::MAX;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 65;

/// 単位元が定義される `T -> T -> T`型の演算
pub trait Monoid: Sized {
    fn identity() -> Self;
    fn op(x: &Self, y: &Self) -> Self;
    fn fold(v: &[Self]) -> Self {
        v.iter().fold(Self::identity(), |a, b| Self::op(&a, b))
    }
}
/// Monoidトレイトの自動実装マクロ
///
/// 一行目にモノイド名、
/// 二行目に単位元
/// 三行目に`2引数を取って、同型の演算結果を返すクロージャを渡す
///
/// ```example
/// monoid_def! {
///     Max<usize>,
///     std::usize::MIN,
///     |x: usize, y: usize| x.max(y)
/// }
/// ```
///
#[macro_export]
macro_rules ! monoid_def {{$ M : ident <$ t : ty >, $ id : expr , $ me : expr } => {# [derive (Debug , Clone , Copy ) ] pub struct $ M ($ t ) ; impl Monoid for $ M {fn identity () -> Self {$ M ($ id ) } fn op (x : & Self , y : & Self ) -> Self {let f = $ me ; $ M (f (x . 0 , y . 0 ) ) } } impl Into <$ M > for $ t {fn into (self ) -> $ M {$ M (self ) } } } ; }

monoid_def! {
    Sum<usize>,
    0,
    |a, b| a + b
}

// code...
// #[fastout]
fn main() {
    input! {
        n: usize, d: usize, a: i64,
        mut enemy: [(usize, i64); n]
    }

    enemy.sort();

    let mut range = Vec::new();
    let p = enemy.iter().map(|x| x.0).collect_vec();
    let h = enemy.iter().map(|x| x.1).collect_vec();
    for i in p.iter() {
        let j = upper_bound(&p, &(*i + 2 * d));
        range.push(j);
    }

    let mut ans = 0usize;
    let mut t = vec![0; n + 1];
    for l in 0..n {
        if l > 0 {
            t[l] += t[l-1];
        }

        let mut rest = h[l] - t[l];
        if rest <= 0 {
            continue;
        }
        let c = (rest as f64 / a as f64).ceil() as usize;
        ans += c;
        t[l] += c as i64 * a;
        t[range[l]] -= c as i64 * a;
    }

    println!("{}", ans);
}


/// # Usage
///
/// `T`は基本的にusizeが入る想定
///
/// `pred`について`l`側が`true`、
/// `r`側が`false`を返すような単調性を持っているとき、
///
/// `pred`を満たす`T`の中で最も大きいものを求める。
///
/// 最初に`l`と`r`について`pred`がそれぞれ`true`、`false`を返すかどうかを調べるので、
/// 範囲は閉空間で指定して良い。
///
/// 返り値`res`は必ず、
///
/// Some(inner) (l <= inner <= r) | None
///
/// になる
///
/// ```rust
/// use prcn_lib::binary_search::binary_search;
///
/// let v = vec![1, 3, 3, 3, 4, 6, 7, 7, 8, 10];
/// assert_eq!(3, binary_search(|i| v[i] < 4, 0, v.len() - 1).unwrap());
/// assert_eq!(9, binary_search(|i| v[i] <= 10, 0, v.len() - 1).unwrap());
/// ```
pub fn binary_search<T, F>(pred: F, l: T, r: T) -> Option<T>
where
    T: Add<Output = T> + Div<Output = T> + PartialEq + Copy + From<u8>,
    F: Fn(T) -> bool,
{
    if !pred(l) {
        return None;
    }
    if pred(r) {
        return Some(r);
    }
    let mut l = l;
    let mut r = r;
    let two = T::from(2);
    loop {
        let m = (l + r) / two;
        if l == m {
            break Some(l);
        }
        if pred(m) {
            l = m;
        } else {
            r = m;
        }
    }
}
/// `v`以上の要素が最初に現れるindex
///
/// ```rust
/// use prcn_lib::binary_search::lower_bound;
///
/// let v: &[i32] = &[1, 3, 3, 4, 5];
/// assert_eq!(lower_bound(v, &0), 0);
/// assert_eq!(lower_bound(v, &1), 0);
/// assert_eq!(lower_bound(v, &2), 1);
/// assert_eq!(lower_bound(v, &3), 1);
/// assert_eq!(lower_bound(v, &4), 3);
/// assert_eq!(lower_bound(v, &5), 4);
/// assert_eq!(lower_bound(v, &999), 5);
/// ```
pub fn lower_bound<T: PartialOrd>(v: &[T], val: &T) -> usize {
    let t = binary_search(|x| v[x] < *val, 0, v.len() - 1);
    match t {
        Some(e) => e + 1,
        None => 0,
    }
}
/// `v`より大きい要素が最初に現れるindex
///
/// ```rust
/// use prcn_lib::binary_search::upper_bound;
///
/// let v: &[i32] = &[1, 3, 3, 4, 5];
/// assert_eq!(upper_bound(v, &0), 0);
/// assert_eq!(upper_bound(v, &1), 1);
/// assert_eq!(upper_bound(v, &2), 1);
/// assert_eq!(upper_bound(v, &3), 3);
/// assert_eq!(upper_bound(v, &4), 4);
/// assert_eq!(upper_bound(v, &5), 5);
/// assert_eq!(upper_bound(v, &999), 5);
/// ```
pub fn upper_bound<T: PartialOrd>(v: &[T], val: &T) -> usize {
    let t = binary_search(|x| v[x] <= *val, 0, v.len() - 1);
    match t {
        Some(e) => e + 1,
        None => 0,
    }
}