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: Runtime Error)

use std::io::stdin;

fn main() {
    let mut stack = [0; 3];
    // 0: モンスター数, 1: 爆弾の範囲, 2: 爆弾のダメージnn
    {
        let mut input = String::new();
        stdin().read_line(&mut input);
        for (i, j) in input.split_whitespace().enumerate() {
            stack[i] = j.parse::<i32>().unwrap();
        }
    }

    let mut each_location_and_hp: Vec<Vec<i32>> = Vec::new();
    // 0: location, 1: hp
    for i in 0..stack[0] {
        let mut input = String::new();
        stdin().read_line(&mut input);
        each_location_and_hp.push(
            input.split_whitespace()
                .map(|x| x.parse::<i32>().unwrap())
                .collect()
        )
    }
    each_location_and_hp.sort();
    each_location_and_hp.reverse();

    let mut used_bombs: i64 = 0;
    let mut effected_range_by_bomb = 0;
    let mut using_bomb_on_this_time = 0;
    let mut index: usize = 0;

    let bomb_range = stack[1] * 2;
    let damage = stack[2];

    while &each_location_and_hp.len() > &0 {
    // loop {
    // for (i, mons) in each_location_and_hp.iter().enumerate() {
        // モンスターを取得
        // let next_monster = mons;
        {
            let next_monster = each_location_and_hp.pop().unwrap();
            //.... 最初のモンス

            // すでに死んでた時は次のループに
            if next_monster[1] <= 0 { continue }

            // 爆弾の範囲を指定
            effected_range_by_bomb = next_monster[0] + bomb_range;
            using_bomb_on_this_time = (next_monster[1] + damage -1) / damage;
            used_bombs += using_bomb_on_this_time as i64;
            using_bomb_on_this_time *= damage;

        }

        // for 内で使うインデックスを変更（配列の後ろの方から取得するように変更）
        index = each_location_and_hp.len() - 1 as usize;
        for i in 0..bomb_range {
            // すでに死んでた時は次のループ
            if each_location_and_hp[index][1] <= 0 { continue }

            //爆弾の巻き添えになったとき
            if each_location_and_hp[index][0] <= effected_range_by_bomb {
                // hpを減算
                each_location_and_hp[index][1] -= using_bomb_on_this_time;
            } else {
                //巻き添え範囲から出た時はループ脱出
                break;
            }
        }
    }
    println!("{}", used_bombs);
}