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.15.1) (judge verdict: Accepted)

#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn bisearch_left(xs: &Vec<i64>, x: i64) -> usize {
    return 0;
    // x 以上の左端
    // if xs[0] >= x { return 0 }
    // let n = xs.len();
    // let mut left = 0;
    // let mut right = n - 1;
    // for _ in 0..20 {
    //     let mid = (left + right) / 2;
    //     if xs[mid] < x {
    //         left = mid;
    //     } else {
    //         right = mid;
    //     }
    // }
    // right
}

fn bisearch_right(xs: &Vec<i64>, x: i64) -> usize {
    // x 以下の右端
    let n = xs.len();
    let mut left = 0;  // xs[left] <= x
    let mut right = n - 1;  // xs[right] > x
    if xs[right] <= x { return right }
    for _ in 0..20 {
        let mid = (left + right) / 2;
        if xs[mid] <= x {
            left = mid;
        } else {
            right = mid;
        }
    }
    left
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let d: i64 = sc.cin();
    let a: i64 = sc.cin();
    let mut es: Vec<_> = (0..n).map(|_| {
        let x: i64 = sc.cin();
        let h: i64 = sc.cin();
        (x, h)
    }).collect();
    es.sort();

    let xs: Vec<_> = es.iter().map(|item| item.0).collect();
    let hs: Vec<_> = es.iter().map(|item| item.1).collect();

    let ys: Vec<(usize, usize)> = (0..n).map(|i|
        (bisearch_left(&xs, xs[i]), bisearch_right(&xs, xs[i] + 2 * d))
    ).collect();

    let mut h_diff = vec![0; n];
    for i in 0..n-1 {
        h_diff[i] = hs[i+1] - hs[i];
    }
    // trace!(&hs);
    // trace!(&xs);
    // trace!(&ys);
    // trace!(&h_diff);

    let mut ans = 0;

    let mut acc = hs[0];
    for i in 0..n {
        // trace!(acc);
        let m = if acc <= 0 {
            0
        } else {
            (acc + a - 1) / a
        };
        // trace!(m);
        ans += m;
        acc -= a * m;
        // if ys[i].0 > 0 {
        //     h_diff[ys[i].0-1] -= a * m;
        // }
        // if ys[i].1 > 0 {
            h_diff[ys[i].1] += a * m;
        // }
        acc += h_diff[i];
        // trace!(&h_diff);

    }

    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}