Language: C++

z#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

enum queryType { SUM, MAX, MIN };
template<typename T>
struct LazySegTree {
  queryType type;
  int n;
  T init; // 単位元(初期値)
  vector<T> node, lazy;
  vector<int> lazyFlag;
  function<T(T&, T&)> calc; // 子ノード2つから親ノードのデータにする処理
  void setType() {
    switch (type) {
      case SUM:
        init = 0;
        calc = [](T& v1, T& v2) { return v1 + v2; };
        break;
      case MAX:
        init = std::numeric_limits<T>::lowest();
        calc = [](T& v1, T& v2) { return (v1 > v2) ? v1 : v2; };
        break;
      case MIN:
        init = std::numeric_limits<T>::max();
        calc = [](T& v1, T& v2) { return (v1 < v2) ? v1 : v2; };
        break;
    }
  }
  LazySegTree(int sz, queryType type) : type(type) {
    setType();
    // 最下段のノード数は2のべき乗(n)
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, init); // セグメント木全体で必要なノード数は2n-1個である
    lazy.resize(2 * n - 1, 0);
    lazyFlag.resize(2 * n - 1, false);
  }
  LazySegTree(vector<T>& v, queryType type) : type(type) {
    setType();
    // 最下段のノード数は元配列のサイズ以上になる最小の2のべき乗(n)
    int sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, init); // セグメント木全体で必要なノード数は2n-1個である
    lazy.resize(2 * n - 1, 0);
    lazyFlag.resize(2 * n - 1, false);
    // 最下段に値を入れたあとに、下の段から順番に値を入れる
    // 値を入れるには、自分の子の2値を参照すれば良い
    // ノードiの親は(i-1)/2、子は(2i+1,2i+2)で見つける
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--) node[i] = calc(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(int i, T v) {
    i += (n - 1); // 最下段のノードにアクセスする
    // 最下段のノードを更新したら、あとは親に上って更新していく
    node[i] = v;
    while (i > 0) {
      i = (i - 1) / 2; // 1つ親にする
      node[i] = calc(node[2 * i + 1], node[2 * i + 2]);
    }
  }
  // k 番目のノードについて遅延評価を行う
  void eval(int k, int l, int r) {
    if (type == SUM) {
      // 遅延配列が空でない場合、自ノード及び子ノードへの値の伝播が起こる
      if (lazy[k] != 0) {
        node[k] += lazy[k];
        // 最下段かどうかのチェックをしよう
        // 子ノードは親ノードの 1/2 の範囲であるため、伝播させるときは半分にする
        if (r - l > 1) {
          lazy[2 * k + 1] += lazy[k] / 2;
          lazy[2 * k + 2] += lazy[k] / 2;
        }
        // 伝播が終わったので、自ノードの遅延配列を空にする
        lazy[k] = 0;
      }
    } else {
      if (lazyFlag[k]) {
        node[k] = lazy[k];
        // 最下段かどうかのチェックをしよう
        if (r - l > 1) {
          lazy[2 * k + 1] = lazy[k];
          lazy[2 * k + 2] = lazy[k];
          lazyFlag[2 * k + 1] = true;
          lazyFlag[2 * k + 2] = true;
        }
        // 伝播が終わったので、自ノードの遅延配列を終了する
        lazyFlag[k] = false;
      }
    }
  }
  // 要求区間 [a, b) 中の要素に一様にvを加算
  void add(int a, int b, T v, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    // k 番目のノードに対して遅延評価を行う
    eval(k, l, r);
    // 範囲外なら何もしない
    if (b <= l || r <= a) return;
    // 完全に被覆しているならば、遅延配列に値を入れた後に評価
    if (a <= l && r <= b) {
      if (type == SUM) {
        lazy[k] += (r - l) * v;
      } else {
        lazy[k] = v;
        lazyFlag[k] = true;
      }
      eval(k, l, r);
    }
    // そうでないならば、子ノードの値を再帰的に計算して、
    // 計算済みの値をもらってくる
    else {
      add(a, b, v, 2 * k + 1, l, (l + r) / 2);
      add(a, b, v, 2 * k + 2, (l + r) / 2, r);
      node[k] = calc(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  // 要求区間 [a, b) 中の要素のquery
  // k := 自分がいるノードのインデックス
  // 対象区間は [l, r) にあたる
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    // 最初に呼び出されたときの対象区間は [0, n)
    if (r < 0) r = n;
    // 要求区間と対象区間が交わらない -> 適当に返す
    if (r <= a || b <= l) return init;
    // 関数が呼び出されたら評価！
    eval(k, l, r);
    // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
    if (a <= l && r <= b) return node[k];
    // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
    // 左側の子を vl ・ 右側の子を vr としている
    // 新しい対象区間は、現在の対象区間を半分に割ったもの
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return calc(vl, vr);
  }
};

void solve() {
  ll n, d, a;
  cin >> n >> d >> a;
  vector<P> m(n);
  rep(i, n) cin >> m[i].first >> m[i].second;
  sort(m.begin(), m.end());
  LazySegTree<ll> st(n + 1, SUM);
  rep(i, n) st.update(i, m[i].second);
  d = d * 2;
  ll ans = 0;
  rep(i, n) {
    ll h = st.query(i, i + 1);
    if (h > 0) {
      ll hit = (h + a - 1) / a;
      ans += hit;
      ll damage = hit * a;
      int r = upper_bound(m.begin(), m.end(), P(m[i].first + d, INF)) - m.begin();
      st.add(i, r, -damage);
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | z#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'z' does not name a type
    1 | z#include <bits/stdc++.h>
      | ^
a.cc:15:9: error: 'vector' does not name a type
   15 | typedef vector<int> vi;
      |         ^~~~~~
a.cc:16:9: error: 'vector' does not name a type
   16 | typedef vector<vi> vvi;
      |         ^~~~~~
a.cc:17:9: error: 'vector' does not name a type
   17 | typedef vector<ll> vl;
      |         ^~~~~~
a.cc:18:9: error: 'vector' does not name a type
   18 | typedef vector<vl> vvl;
      |         ^~~~~~
a.cc:19:9: error: 'pair' does not name a type
   19 | typedef pair<ll, ll> P;
      |         ^~~~
a.cc:30:3: error: 'vector' does not name a type
   30 |   vector<T> node, lazy;
      |   ^~~~~~
a.cc:31:3: error: 'vector' does not name a type
   31 |   vector<int> lazyFlag;
      |   ^~~~~~
a.cc:32:3: error: 'function' does not name a type; did you mean 'union'?
   32 |   function<T(T&, T&)> calc; // 子ノード2つから親ノードのデータにする処理
      |   ^~~~~~~~
      |   union
a.cc:58:21: error: expected ')' before '<' token
   58 |   LazySegTree(vector<T>& v, queryType type) : type(type) {
      |              ~      ^
      |                     )
a.cc: In member function 'void LazySegTree<T>::setType()':
a.cc:37:9: error: 'calc' was not declared in this scope
   37 |         calc = [](T& v1, T& v2) { return v1 + v2; };
      |         ^~~~
a.cc:40:21: error: 'numeric_limits' is not a member of 'std'
   40 |         init = std::numeric_limits<T>::lowest();
      |                     ^~~~~~~~~~~~~~
a.cc:40:37: error: expected primary-expression before '>' token
   40 |         init = std::numeric_limits<T>::lowest();
      |                                     ^
a.cc:40:40: error: '::lowest' has not been declared
   40 |         init = std::numeric_limits<T>::lowest();
      |                                        ^~~~~~
a.cc:44:21: error: 'numeric_limits' is not a member of 'std'
   44 |         init = std::numeric_limits<T>::max();
      |                     ^~~~~~~~~~~~~~
a.cc:44:37: error: expected primary-expression before '>' token
   44 |         init = std::numeric_limits<T>::max();
      |                                     ^
a.cc:44:40: error: '::max' has not been declared; did you mean 'maxs'?
   44 |         init = std::numeric_limits<T>::max();
      |                                        ^~~
      |                                        maxs
a.cc: In constructor 'LazySegTree<T>::LazySegTree(int, queryType)':
a.cc:54:5: error: 'node' was not declared in this scope
   54 |     node.resize(2 * n - 1, init); // セグメント木全体で必要なノード数は2n-1個である
      |     ^~~~
a.cc:55:5: error: 'lazy' was not declared in this scope
   55 |     lazy.resize(2 * n - 1, 0);
      |     ^~~~
a.cc:56:5: error: 'lazyFlag' was not declared in this scope
   56 |     lazyFlag.resize(2 * n - 1, false);
      |     ^~~~~~~~
a.cc: In member function 'void LazySegTree<T>::update(int, T)':
a.cc:76:5: error: 'node' was not declared in this scope
   76 |     node[i] = v;
      |     ^~~~
a.cc:79:17: error: there are no arguments to 'calc' that depend on a template parameter, so a declaration of 'calc' must be available [-fpermissive]
   79 |       node[i] = calc(node[2 * i + 1], node[2 * i + 2]);
      |                 ^~~~
a.cc:79:17: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: In member function 'void LazySegTree<T>::eval(int, int, int)':
a.cc:86:11: error: 'lazy' was not declared in this scope
   86 |       if (lazy[k] != 0) {
      |           ^~~~
a.cc:87:9: error: 'node' was not declared in this scope
   87 |         node[k] += lazy[k];
      |         ^~~~
a.cc:98:11: error: 'lazyFlag' was not declared in this scope
   98 |       if (lazyFlag[k]) {
      |           ^~~~~~~~
a.cc:99:9: error: 'node' was not declared in this scope
   99 |         node[k] = lazy[k];
      |         ^~~~
a.cc:99:19: error: 'lazy' was not declared in this scope
   99 |         node[k] = lazy[k];
      |                   ^~~~
a.cc: In member function 'void LazySegTree<T>::add(int, int, T, int, int, int)':
a.cc:122:9: error: 'lazy' was not declared in this scope
  122 |         lazy[k] += (r - l) * v;
      |         ^~~~
a.cc:124:9: error: 'lazy' was not declared in this scope
  124 |         lazy[k] = v;
      |         ^~~~
a.cc:125:9: error: 'lazyFlag' was not declared in this scope
  125 |         lazyFlag[k] = true;
      |         ^~~~~~~~
a.cc:134:7: error: 'node' was not declared in this scope
  134 |       node[k] = calc(node[2 * k + 1], node[2 * k + 2]);
      |       ^~~~
a.cc:134:17: error: there are no arguments to 'calc' that depend on a template parameter, so a declaration of 'calc' must be available [-fpermissive]
  134 |       node[k] = calc(node[2 * k + 1], node[2 * k + 2]);
      |                 ^~~~
a.cc: In member function 'T LazySegTree<T>::query(int, int, int, int, int)':
a.cc:148:34: error: 'node' was not declared in this scope
  148 |     if (a <= l && r <= b) return node[k];
      |                                  ^~~~
a.cc: In function 'void solve()':
a.cc:160:3: error: 'cin' was not declared in this scope
  160 |   cin >> n >> d >> a;
      |   ^~~
a.cc:161:3: error: 'vector' was not declared in this scope
  161 |   vector<P> m(n);
      |   ^~~~~~
a.cc:161:10: error: 'P' was not declared in this scope
  161 |   vector<P> m(n);
      |          ^
a.cc:161:13: error: 'm' was not declared in this scope
  161 |   vector<P> m(n);
      |             ^
a.cc:163:3: error: 'sort' was not declared in this scope; did you mean 'short'?
  163 |   sort(m.begin(), m.end());
      |   ^~~~
      |   short
a.cc:174:15: error: 'upper_bound' was not declared in this scope
  174 |       int r = upper_bound(m.begin(), m.end(), P(m[i].first + d, INF)) - m.begin();
      |               ^~~~~~~~~~~
a.cc:178:3: error: 'cout' was not declared in this scope
  178 |   cout << ans << endl;
      |   ^~~~
a.cc:178:18: error: 'endl' was not declared in this scope
  178 |   cout << ans << endl;
      |                  ^~~~
a.cc: In function 'int main()':
a.cc:182:3: error: 'cin' was not declared in this scope
  182 |   cin.tie(0);
      |   ^~~
a.cc:183:3: error: 'ios' has not been declared
  183 |   ios::sync_with_stdio(false);
      |   ^~~
a.cc:184:3: error: 'cout' was not declared in this scope
  184 |   cout << fixed << setprecision(15);
      |   ^~~~
a.cc:184:11: error: 'fixed' was not declared in this scope
  184 |   cout << fixed << setprecision(15);
      |           ^~~~~
a.cc:184:20: error: 'setprecision' was not declared in this scope
  184 |   cout << fixed << setprecision(15);
      |                    ^~~~~~~~~~~~
a.cc: In instantiation of 'T LazySegTree<T>::query(int, int, int, int, int) [with T = long long int]':
a.cc:169:20:   required from here
  169 |     ll h = st.query(i, i + 1);
      |            ~~~~~~~~^~~~~~~~~~
a.cc:154:16: error: 'calc' was not declared in this scope
  154 |     return calc(vl, vr);
      |            ~~~~^~~~~~~~