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: Wrong Answer)

#[macro_use]
mod input_mcr {
    // ref: tanakh <https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8>
    // diff: using Parser
    #[macro_export(local_inner_macros)]
    macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut parser = Parser::from_str($s);
        input_inner!{parser, $($r)*}
    };
    (parser = $parser:ident, $($r:tt)*) => {
        input_inner!{$parser, $($r)*}
    };
    (new_stdin_parser = $parser:ident, $($r:tt)*) => {
        let stdin = std::io::stdin();
        let reader = std::io::BufReader::new(stdin.lock());
        let mut $parser = Parser::new(reader);
        input_inner!{$parser, $($r)*}
    };
    ($($r:tt)*) => {
        input!{new_stdin_parser = parser, $($r)*}
    };
}

    #[macro_export(local_inner_macros)]
    macro_rules! input_inner {
    ($parser:ident) => {};
    ($parser:ident, ) => {};
    ($parser:ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($parser, $t);
        input_inner!{$parser $($r)*}
    };
}

    #[macro_export(local_inner_macros)]
    macro_rules! read_value {
    ($parser:ident, ( $($t:tt),* )) => {
        ( $(read_value!($parser, $t)),* )
    };
    ($parser:ident, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($parser, $t)).collect::<Vec<_>>()
    };
    ($parser:ident, chars) => {
        read_value!($parser, String).chars().collect::<Vec<char>>()
    };
    ($parser:ident, char_) => {
        read_value!($parser, String).chars().collect::<Vec<char>>()[0]
    };
    ($parser:ident, usize1) => {
        read_value!($parser, usize) - 1
    };
    ($parser:ident, line) => {
        $parser.next_line()
    };
    ($parser:ident, line_) => {
        $parser.next_line().chars().collect::<Vec<char>>()
    };
    ($parser:ident, i64_) => {
        $parser.fast_i64()
    };
    ($parser:ident, usize_) => {
        $parser.fast_i64() as usize
    };
    ($parser:ident, usize1_) => {
        ($parser.fast_i64() - 1) as usize
    };
    ($parser:ident, $t:ty) => {
        $parser.next::<$t>().expect("Parse error")
    };
}

    use std::io;
    use std::io::BufRead;
    use std::str;

    // ref: tatsuya6502 <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e>
    // ref: wariuni <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e#comment-7040a5ae96305e884eb9>
    // diff: using std::io::BufRead::fill_buf()
    pub struct Parser<R> {
        pub reader: R,
        buf: Vec<u8>,
        pos: usize,
    }

    impl Parser<io::Empty> {
        pub fn from_str(s: &str) -> Parser<io::Empty> {
            Parser {
                reader: io::empty(),
                buf: s.as_bytes().to_vec(),
                pos: 0,
            }
        }
    }

    impl<R: BufRead> Parser<R> {
        pub fn new(reader: R) -> Parser<R> {
            Parser {
                reader: reader,
                buf: vec![],
                pos: 0,
            }
        }
        pub fn update_buf(&mut self) {
            self.buf.clear();
            self.pos = 0;
            loop {
                let (len, complete) = {
                    let buf2 = self.reader.fill_buf().unwrap();
                    self.buf.extend_from_slice(buf2);
                    let len = buf2.len();
                    (len, buf2[len - 1] <= 0x20)
                };
                self.reader.consume(len);
                if complete {
                    break;
                }
            }
        }
        pub fn next<T: str::FromStr>(&mut self) -> Result<T, T::Err> {
            loop {
                let mut begin = self.pos;
                while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                    begin += 1;
                }
                let mut end = begin;
                while end < self.buf.len() && (self.buf[end] > 0x20) {
                    end += 1;
                }
                if begin != self.buf.len() {
                    self.pos = end;
                    return unsafe { str::from_utf8_unchecked(&self.buf[begin..end]) }.parse::<T>();
                } else {
                    self.update_buf();
                }
            }
        }
        pub fn next_line(&mut self) -> String {
            loop {
                let mut begin = self.pos;
                if begin < self.buf.len() && (self.buf[begin] < 0x20) {
                    begin += 1;
                }
                let mut end = begin;
                while end < self.buf.len() && (self.buf[end] >= 0x20) {
                    end += 1;
                }
                if begin != self.buf.len() {
                    self.pos = end;
                    return unsafe { str::from_utf8_unchecked(&self.buf[begin..end]) }.to_string();
                } else {
                    self.update_buf();
                }
            }
        }
        pub fn fast_i64(&mut self) -> i64 {
            loop {
                let mut begin = self.pos;
                while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                    begin += 1;
                }
                if begin == self.buf.len() {
                    self.update_buf();
                    continue;
                }
                let mut res = 0;
                let (is_positive, mut end) = match self.buf[begin] {
                    b'+' => (true, begin + 1),
                    b'-' => (false, begin + 1),
                    _ => (true, begin),
                };
                while end < self.buf.len() && (self.buf[end] > 0x20) {
                    res = res * 10 + (self.buf[end] as i64 - '0' as i64);
                    end += 1;
                }
                if begin != self.buf.len() {
                    self.pos = end;
                    return if is_positive { res } else { -res };
                } else {
                    self.update_buf();
                }
            }
        }
    }
}

mod num {
    use std::ops::*;

    pub trait Num:
        Add<Output = Self> + AddAssign + Mul<Output = Self> + PartialOrd + Ord + Clone + Copy
    {
        fn zero() -> Self;
        fn one() -> Self;
    }
    impl Num for usize {
        fn zero() -> Self {
            0
        }
        fn one() -> Self {
            1
        }
    }
    impl Num for i64 {
        fn zero() -> Self {
            0
        }
        fn one() -> Self {
            1
        }
    }
}

mod segment_tree_add {
    use num::*;

    #[derive(Clone, Copy, Debug)]
    struct Entry<T> {
        // merge
        sum: T,
        // push
        range_add: T,
    }

    impl<T: Num> Entry<T> {
        pub fn new(x: T) -> Entry<T> {
            Entry {
                sum: x,
                range_add: T::zero(),
            }
        }
        pub fn merge(l: &Entry<T>, r: &Entry<T>) -> Entry<T> {
            Entry {
                sum: l.sum + r.sum,
                range_add: T::zero(),
            }
        }
        pub fn push(xs: &mut Vec<Entry<T>>, i: usize) {
            let l = 2 * i;
            let r = 2 * i + 1;
            let range_add = xs[i].range_add();
            for &k in &[l, r] {
                let k_range_add = xs[k].range_add();
                xs[k].set_range_add(range_add + k_range_add);
            }
        }
        pub fn add(&mut self, x: T) {
            self.sum += x;
        }
        pub fn sum(&self) -> T {
            self.sum
        }
        pub fn range_add(&self) -> T {
            self.range_add
        }
        pub fn set_range_add(&mut self, x: T) {
            self.range_add = x;
        }
    }

    #[derive(Debug)]
    pub struct SegmentTreeAdd<T> {
        n: usize,
        xs: Vec<Entry<T>>,
    }

    impl<T: Num> SegmentTreeAdd<T> {
        pub fn new(xs: &Vec<T>) -> SegmentTreeAdd<T> {
            let n = xs.len();
            let n2 = n.next_power_of_two();
            let mut res = vec![];
            for _ in n..n2 {
                res.push(Entry::<T>::new(xs[xs.len() - 1]));
            }
            for &x in xs.iter().rev() {
                res.push(Entry::<T>::new(x));
            }
            for i in (1..n2).rev() {
                let l = 2 * n2 - (2 * i) - 1;
                let r = 2 * n2 - (2 * i + 1) - 1;
                let e = Entry::merge(&res[l], &res[r]);
                res.push(e);
            }
            let t = res[res.len() - 1];
            res.push(t);
            res.reverse();
            SegmentTreeAdd::<T> { n: n2, xs: res }
        }
        pub fn add(&mut self, i: usize, x: T) {
            self.xs[self.n + i].add(x);
            let mut k = (self.n + i) / 2;
            while k != 0 {
                self.xs[k] = Entry::merge(&self.xs[2 * k], &self.xs[2 * k + 1]);
                k /= 2;
            }
        }
        pub fn range_sum(&mut self, l: usize, r: usize) -> T {
            {
                let mut l = self.n + l;
                let mut r = self.n + r;
                let mut buf = vec![];
                while l < r {
                    if l & 1 != 0 {
                        buf.push(l / 2);
                        l += 1;
                    }
                    if r & 1 != 0 {
                        r -= 1;
                        buf.push(r / 2);
                    }
                    l /= 2;
                    r /= 2;
                }
                while l != 0 && l != 1 {
                    buf.push(l / 2);
                    l /= 2;
                }
                for &k in buf.iter().rev() {
                    Entry::push(&mut self.xs, k);
                }
            }
            let mut l = self.n + l;
            let mut r = self.n + r;
            let mut res = T::zero();
            let mut size = T::one();
            while l < r {
                if l & 1 != 0 {
                    res += self.xs[l].sum() + size * self.xs[l].range_add();
                    l += 1;
                }
                if r & 1 != 0 {
                    r -= 1;
                    res += self.xs[r].sum() + size * self.xs[r].range_add();
                }
                l /= 2;
                r /= 2;
                size = size + size;
            }
            res
        }
        pub fn range_add(&mut self, l: usize, r: usize, x: T) {
            let mut l = self.n + l;
            let mut r = self.n + r;
            while l < r {
                if l & 1 != 0 {
                    self.xs[l].set_range_add(x);
                    l += 1;
                }
                if r & 1 != 0 {
                    r -= 1;
                    self.xs[r].set_range_add(x);
                }
                l /= 2;
                r /= 2;
            }
        }
    }
}

use input_mcr::*;
use std::cmp::*;

use segment_tree_add::*;

fn main() {
    input! {
        n: usize,
        d: i64,
        a: i64,
        xs: [(i64,i64); n],
    }
    let mut xs = xs;
    xs.sort();
    let mut tree = SegmentTreeAdd::new(&xs.iter().map(|x| x.1).collect());
    let mut res = 0i64;
    let ys: Vec<i64> = xs.iter().map(|x| x.0).collect();
    for i in 0..n {
        let v = tree.range_sum(i, i + 1);
        // eprintln!("v = {}", v);
        if v > 0 {
            res += (v + a - 1) / a;
            let r = ys[i] + 2 * d;
            let right = match ys.binary_search(&r) {
                Ok(t) => t + 1,
                Err(t) => t,
            };
            tree.range_add(i, right, -((v + a - 1) / a * a));
        }
    }
    println!("{}", res);
}