func_code_string: #include <bits/stdc++.h>   using namespace std;   int d, n, m, b[200005];   int mn[200005 << 2];   long long ans;   struct node {     int x;     long long p;     bool operator<(const node &a) const { return x < a.x; }   } a[200005];   int check(int x, int y) { return a[x].p < a[y].p ? x : y; }   void build(int l, int r, int rt) {     if (l == r) {       mn[rt] = l;       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     mn[rt] = check(mn[rt << 1], mn[rt << 1 | 1]);   }   int get_mn(int l, int r, int rt, int L, int R) {     if (L == l && R == r) return mn[rt];     int mid = (l + r) >> 1;     if (R <= mid)       return get_mn(l, mid, rt << 1, L, R);     else if (L > mid)       return get_mn(mid + 1, r, rt << 1 | 1, L, R);     else       return check(get_mn(l, mid, rt << 1, L, mid),                    get_mn(mid + 1, r, rt << 1 | 1, mid + 1, R));   }   int main() {     cin >> d >> n >> m;     for (int i = 1; i <= m; i++) scanf( %d%I64d , &a[i].x, &a[i].p);     sort(a + 1, a + m + 1);     a[++m].x = d;     a[0].p = 0x3f3f3f3f;     build(1, m, 1);     for (int i = 1; i <= m; i++) b[i] = a[i].x;     int now = n, i = 0, j = 1, t, k;     while (i < m) {       t = upper_bound(b + 1, b + m + 1, a[i].x + n) - b - 1;       if (t == i) {         puts( -1 );         return 0;       }       t = upper_bound(b + 1, b + m + 1, a[i].x + now) - b - 1;       k = (t > i ? get_mn(1, m, 1, i + 1, t) : 0);       if (a[k].p <= a[i].p) {         now -= (a[k].x - a[i].x);         i = k;       } else {         t++;         while (t <= m && a[t].x - a[i].x <= n) {           if (a[t].p <= a[i].p) {             ans = (ans + (a[t].x - a[i].x - now) * a[i].p);             now = 0;             i = t;             break;           }           t++;         }         if (a[t].x - a[i].x > n) {           t = upper_bound(b + 1, b + m + 1, a[i].x + n) - b - 1;           k = get_mn(1, m, 1, i + 1, t);           ans = (ans + (n - now) * a[i].p);           now = (n - (a[k].x - a[i].x));           i = k;         }       }     }     cout << ans << endl;   }   