Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <set>
#include <queue>
#include <assert.h>
#include <cmath>
#include <map>
#include <bitset>


using std::cerr;
using std::cin;
using std::cout;
using std::pair;
using std::string;
using std::vector;
//region
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b); i >= (b); --i)
#define rep(i, n) for (unsigned i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n)-1; i >= 0; --i)
#define repr1(i, n) for (int i = (n); i > 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define sz(x) (int((x).size()))
#define mset(v, n) std::memset((v), n, sizeof(v))
#define BIT(N) (1LL << (N))
#define each(i, v) for (auto&& i : (v))
#define unless(f) if(!(f))
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using vint = vector<int>;
using vlong = vector<ll>;
using vstr = vector<string>;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpll = vector<pll>;
using vvi = vector<vint>;
using vvl = vector<vlong>;
vector<string> split(const string &s, const string &delim) {
  vector<string> res;
  uint pos = 0;
  while (true) {
    const size_t found = s.find(delim, pos);
    if (found < 0) {
      res.push_back(s.substr(pos));
      break;
    }
    res.push_back(s.substr(pos, found - pos));
    pos = found + delim.size();
  }
  return res;
}
template<typename T> string join(vector<T> &vec, const string &sep) {
  size_t size = vec.size();
  if (!size) return "";
  std::stringstream ss;
  for (int i = 0; i < size - 1; i++)
    ss << vec[i] << sep;
  ss << vec[size - 1];
  return ss.str();
}
template<typename T> std::istream &operator>>(std::istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template<typename Iter> inline void print(const Iter &first, const Iter &last, const std::string &d, bool endline) {
  cout << *first;
  for (Iter iter = first + 1; iter < last; ++iter) {
    cout << d << *iter;
  }
  if (endline) cout << "\n";
}
constexpr ll powmod(ll a, ull b, uint p) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) res = res * a % p;
    a = a * a % p;
    b >>= 1u;
  }
  return res;
}
template<class T> bool chmax(T &a, const T &b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, const T &b) { return a > b ? (a = b, true) : false; }
template <typename T> void bsort(vector<T>& v) { std::sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T>& v) { std::sort(v.begin(), v.end(), std::greater<T>()); }
struct iii {
    iii() {
      cin.tie(nullptr); cout.tie(nullptr);
      std::ios::sync_with_stdio(false);
      cout << std::fixed << std::setprecision(16);
    }
} init;
//endregion

void solve();

int main() {
  int t = 1;
//  scanf("%d", &t);
  // cin >> t;
  rep(i, t) solve();
  return 0;
}

template< typename OperatorMonoid >
struct DualSegmentTree {
    using H = std::function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;

    int sz, height;
    vector< OperatorMonoid > lazy;
    const H h;
    const OperatorMonoid OM0;

    DualSegmentTree(int n, const H h, const OperatorMonoid &OM0) : h(h), OM0(OM0) {
      sz = 1;
      height = 0;
      while(sz < n) sz <<= 1, height++;
      lazy.assign(2 * sz, OM0);
    }

    inline void propagate(int k) {
      if(lazy[k] != OM0) {
        lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
        lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
        lazy[k] = OM0;
      }
    }

    inline void thrust(int k) {
      for(int i = height; i > 0; i--) propagate(k >> i);
    }

    void update(int a, int b, const OperatorMonoid &x) {
      thrust(a += sz);
      thrust(b += sz - 1);
      for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
        if(l & 1) lazy[l] = h(lazy[l], x), ++l;
        if(r & 1) --r, lazy[r] = h(lazy[r], x);
      }
    }

    OperatorMonoid operator[](int k) {
      thrust(k += sz);
      return lazy[k];
    }
};

void solve(){
  int N; ll D, A;
  cin >> N >> D >> A;
  vector<pair<int, ll>> M(N);
  rep(i, N) cin >> M[i].first >> M[i].second;

  bsort(M);
  DualSegmentTree<ll> seg(N, [](ll a, ll b) {
      return a + b;
  }, 0);
  
  rep(i, N) seg.update(i, i+1, M[i].second);
  vint P(N);
  rep(i, N) P[i] = M[i].first;

  ll ans=0;
  rep(i, N) {
    if(seg[i] <= 0) continue;

    ll hp = seg[i];
    ll cnt = hp / A;

    ans+=cnt;
    if (hp % A) ++cnt;

    ll damage = cnt * A;

    ll max = P[i] + D * 2;
    size_t last = std::upper_bound(all(P), max) - P.begin();
    seg.update(i, last, -damage);
  }
  printf("%d\n", ans);
}


Compiler output:
a.cc:113:20: error: 'function' in namespace 'std' does not name a template type
  113 |     using H = std::function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;
      |                    ^~~~~~~~
a.cc:12:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
   11 | #include <bitset>
  +++ |+#include <functional>
   12 | 
a.cc:117:11: error: 'H' does not name a type
  117 |     const H h;
      |           ^
a.cc:120:34: error: 'H' does not name a type
  120 |     DualSegmentTree(int n, const H h, const OperatorMonoid &OM0) : h(h), OM0(OM0) {
      |                                  ^
a.cc: In constructor 'DualSegmentTree<OperatorMonoid>::DualSegmentTree(int, int, const OperatorMonoid&)':
a.cc:120:68: error: class 'DualSegmentTree<OperatorMonoid>' does not have any field named 'h'
  120 |     DualSegmentTree(int n, const H h, const OperatorMonoid &OM0) : h(h), OM0(OM0) {
      |                                                                    ^
a.cc: In function 'void solve()':
a.cc:161:30: error: invalid user-defined conversion from 'solve()::<lambda(ll, ll)>' to 'int' [-fpermissive]
  161 |   DualSegmentTree<ll> seg(N, [](ll a, ll b) {
      |                              ^~~~~~~~~~~~~~~~
  162 |       return a + b;
      |       ~~~~~~~~~~~~~           
  163 |   }, 0);
      |   ~                           
a.cc:161:30: note: candidate is: 'constexpr solve()::<lambda(ll, ll)>::operator long long int (*)(ll, ll)() const' (near match)
  161 |   DualSegmentTree<ll> seg(N, [](ll a, ll b) {
      |                              ^
a.cc:161:30: note:   no known conversion from 'long long int (*)(ll, ll)' {aka 'long long int (*)(long long int, long long int)'} to 'int'
a.cc:120:36: note:   initializing argument 2 of 'DualSegmentTree<OperatorMonoid>::DualSegmentTree(int, int, const OperatorMonoid&) [with OperatorMonoid = long long int]'
  120 |     DualSegmentTree(int n, const H h, const OperatorMonoid &OM0) : h(h), OM0(OM0) {
      |                            ~~~~~~~~^
a.cc: In instantiation of 'void DualSegmentTree<OperatorMonoid>::update(int, int, const OperatorMonoid&) [with OperatorMonoid = long long int]':
a.cc:165:23:   required from here
  165 |   rep(i, N) seg.update(i, i+1, M[i].second);
      |             ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:143:30: error: 'h' was not declared in this scope
  143 |         if(l & 1) lazy[l] = h(lazy[l], x), ++l;
      |                             ~^~~~~~~~~~~~
a.cc:144:35: error: 'h' was not declared in this scope
  144 |         if(r & 1) --r, lazy[r] = h(lazy[r], x);
      |                                  ~^~~~~~~~~~~~
a.cc: In instantiation of 'void DualSegmentTree<OperatorMonoid>::propagate(int) [with OperatorMonoid = long long int]':
a.cc:136:39:   required from 'void DualSegmentTree<OperatorMonoid>::thrust(int) [with OperatorMonoid = long long int]'
  136 |       for(int i = height; i > 0; i--) propagate(k >> i);
      |                                       ^~~~~~~~~
a.cc:140:7:   required from 'void DualSegmentTree<OperatorMonoid>::update(int, int, const OperatorMonoid&) [with OperatorMonoid = long long int]'
  140 |       thrust(a += sz);
      |       ^~~~~~
a.cc:165:23:   required from here
  165 |   rep(i, N) seg.update(i, i+1, M[i].second);
      |             ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:129:28: error: 'h' was not declared in this scope
  129 |         lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
      |                           ~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:130:28: error: 'h' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation
  130 |         lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      |                           ~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:129:28: note: 'h' declared here, later in the translation unit
  129 |         lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
      |                           ~^~~~~~~~~~~~~~~~~~~~~~~~~~