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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

#define lsb(x) (x&(-x))

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int n;
int aib[NMAX];
// the aib is 1 indexed

void update(int x, int position)
{
	position++;
	for(int i = position; i<= n; i+=lsb(i))
		aib[i]+=x;
}

// adds from left but substract from right
void update_range(int x, int left, int right)
{
	update(x,left);
	update(-x,right+1);
}

int query(int position)
{
	position++;
	ll sum = 0;
	for(int i = position; i> 0; i-=lsb(i))
	{
		sum+=aib[i];
	}
	return sum;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int d,a;
    cin >> n >> d >> a;

    vector<pair<int,int> > monsters;

    for(int i =0; i < n; ++i)
    {
		int x, h;
		cin >> x >> h;
		h = (h + a - 1) / a;
		monsters.emplace_back(x,h);
		int toAdd = h;
		if(i)
			toAdd = h - monsters[i-1].second;

		// ca la smenul lui mars vectorul b a[i] = b[0] + b[1] + .. b[i]
		update(toAdd,i);
	}

	sort(monsters.begin(), monsters.end());

	// segment tree or BIT to hold the health of the monsters
	// want to use smenul lui mars pt aib 

	ll ans = 0;
    for(int i =0 ; i < n; ++i)
	{
		// prefix sum (0,i) din b care da elementul i
		int currHp = query(i);

		if(currHp == 0)
			continue;

		int low = i, high = n - 1, mid;
		int ok = -1;

		while(low <= high)
		{
			mid = (low + high) >> 1;
			// find the last monster still hit by a bomb starting from monster[i] location
			if(monsters[mid].first <= monsters[i].first + 2LL * d)
			{
				ok = mid;
				low = mid+1;
			}
			else
			{
				high = mid-1;
			}
		}
		update_range(-currHp,i,ok);
		ans+=currHp;
	}
	cout << ans;

    return 0;
}