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_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

pub trait OpMonoid {
    type T: Clone + PartialEq;
    fn id() -> Self::T;
    fn op(a: &Self::T, b: &Self::T) -> Self::T;
    fn op2(a: &Self::T, b: &Self::T) -> Self::T;
    fn op3(a: &Self::T, b: &i64) -> Self::T;
}
pub struct LazySegTree<M: OpMonoid> {
    n: usize,
    data: Vec<M::T>,
    lazy: Vec<M::T>,
}
impl<M: OpMonoid> LazySegTree<M> {
    pub fn new(n_: usize) -> LazySegTree<M> {
        let mut n = 1 as usize;
        while (n < n_) {
            n *= 2;
        }
        LazySegTree {
            n: n,
            data: vec![M::id().clone(); (2 * n)],
            lazy: vec![M::id().clone(); (2 * n)],
        }
    }
    #[macro_use]
    pub fn update(&mut self, index: usize, v: M::T) {
        let mut k = index + self.n - 1;
        self.data[k] = v;
        while (k > 0) {
            k = (k - 1) / 2;
            self.data[k] = M::op(&self.data[2 * k + 1], &self.data[2 * k + 2]);
        }
    }
    pub fn eval(&mut self, k: usize, l: i32, r: i32) {
        if self.lazy[k] != M::id().clone() {
            if (r - l) > 1 {
                self.lazy[2 * k + 1] = M::op2(&self.lazy[2 * k + 1], &self.lazy[k]);
                self.lazy[2 * k + 2] = M::op2(&self.lazy[2 * k + 2], &self.lazy[k]);
            }
            self.data[k] = M::op2(&self.data[k], &M::op3(&self.lazy[k], &((r - l) as i64)));
            self.lazy[k] = M::id().clone();
        }
    }
    pub fn update_range_sub(&mut self, a: usize, b: usize, v: M::T, k: usize, l: i32, r: i32) {
        let mut r = r;
        if r < 0 {
            r = self.n as i32;
        }
        self.eval(k, l, r);
        if b as i32 <= l || r <= a as i32 {
            return;
        }
        if a as i32 <= l && r <= b as i32 {
            self.lazy[k] = v.clone();
            self.eval(k, l, r);
        } else {
            self.update_range_sub(a, b, v.clone(), 2 * k + 1, l, (l + r) / 2);
            self.update_range_sub(a, b, v.clone(), 2 * k + 2, (l + r) / 2, r);
            self.data[k] = M::op(&self.data[2 * k + 1], &self.data[2 * k + 2]);
        }
    }
    pub fn update_range(&mut self, l: usize, r: usize, v: M::T) {
        self.update_range_sub(l, r, v, 0, 0, -1);
    }
    pub fn query_sub(&mut self, a: usize, b: usize, k: usize, l: i32, r: i32) -> M::T {
        let mut r = r;
        if r < 0 {
            r = self.n as i32
        };
        if b as i32 <= l || r <= a as i32 {
            return M::id();
        }
        self.eval(k, l, r);
        if a as i32 <= l && r <= b as i32 {
            return self.data[k].clone();
        }
        let vl = self.query_sub(a, b, 2 * k + 1, l, (l + r) / 2);
        let vr = self.query_sub(a, b, 2 * k + 2, (l + r) / 2, r);
        return M::op(&vl, &vr);
    }
    pub fn query(&mut self, l: usize, r: usize) -> M::T {
        self.query_sub(l, r, 0, 0, -1)
    }
}
struct SUM;
impl OpMonoid for SUM {
    type T = i64;
    fn id() -> Self::T {
        0
    }
    fn op(a: &Self::T, b: &Self::T) -> Self::T {
        *a + *b
    }
    fn op2(a: &Self::T, b: &Self::T) -> Self::T {
        *a + *b
    }
    fn op3(a: &Self::T, b: &i64) -> Self::T {
        (*a) * (*b)
    }
}

use superslice::*;
fn main() {
    input! {
       N: usize,
       D:usize,
       A:i64,
    }

    let mut ans = 0;
    let mut b = vec![];
    let mut y = vec![];
    for _ in 0..N {
        input! {
            x:usize,
            h:usize,
        }
        b.push((x, h));
        y.push(x);
    }
    b.sort_by_key(|&x| x.0);
    y.sort();
    mydbg!(y);
    let mut seg: LazySegTree<SUM> = LazySegTree::new(N);
    for i in 0..N {
        let (_, h) = b[i];
        seg.update(i, h as i64);
    }
    for i in 0..N {
        let (x, h) = b[i];
        let index = y.upper_bound(&(x + D + D));
        let life = seg.query(i, i + 1);
        if life <= 0 {
            continue;
        }
        let a = (life + A - 1) / A;
        mydbg!(i, index, life, a);
        seg.update_range(i, index, -1 * a * A);
        ans += a;
    }

    echo!(ans);
}