func_code_string: #include <bits/stdc++.h>   using namespace std;   struct node {     long long x, p, id;     bool operator<(const node &a) const { return x < a.x; }   } a[200010];   long long n, v, d, ans, Next[200010];   stack<node> s;   signed main() {     scanf( %lld%lld%lld , &d, &v, &n);     for (long long i = 1; i <= n; i++) scanf( %lld%lld , &a[i].x, &a[i].p);     a[0].p = 1e6 + 1;     a[n + 1].x = d;     sort(a, a + n + 2);     for (long long i = 0; i <= n; i++) {       if (a[i + 1].x - a[i].x > v) {         puts( -1 );         return 0;       }     }     s.push(node{d, 0, n + 1});     for (long long i = n; i >= 1; i--) {       node t = node{0, 0, 0};       while (t = s.top(), t.x - a[i].x > v || t.p > a[i].p) {         s.pop();         if (s.empty()) {           t.id = 0;           break;         }       }       Next[i] = t.id;       s.push(node{a[i].x, a[i].p, i});     }     long long i = 0, now = v;     while (i <= n) {       if (Next[i]) {         long long dis = a[Next[i]].x - a[i].x;         if (dis < now)           now -= dis;         else           ans += a[i].p * (dis - now), now = 0;         i = Next[i];       } else {         ans += a[i].p * (v - now);         now = v - (a[i + 1].x - a[i].x);         i++;       }     }     printf( %lld n , ans);     return 0;   }   