func_code_string: #include <bits/stdc++.h>   using namespace std;   inline long long getnum() {     char c = getchar();     long long num, sign = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (num = 0; c >=  0  && c <=  9 ;) {       c -=  0 ;       num = num * 10 + c;       c = getchar();     }     return num * sign;   }   pair<int, int> P[200050];   int A[200050];   stack<int> Stack;   int main() {     int d = getnum(), tot = getnum(), n = getnum() + 2;     P[1] = make_pair(0, 0);     P[2] = make_pair(d, 0);     for (int i = 3; i <= n; i++) {       int x = getnum(), y = getnum();       P[i] = make_pair(x, y);     }     sort(P + 1, P + n + 1);     Stack.push(n);     for (int i = n - 1; i >= 1; i--) {       while (P[Stack.top()].second > P[i].second) Stack.pop();       A[i] = Stack.top();       Stack.push(i);     }     long long ans = 0;     int cur = 0;     for (int i = 1; i <= n - 1; i++) {       int x = 0, y = A[i];       int to = P[y].first - P[i].first;       if (to > cur) {         int a = to - cur;         if (a + cur > tot) a = (tot - cur);         ans += (long long)a * P[i].second;         cur += a;       }       cur -= (P[i + 1].first - P[i].first);       if (cur < 0) {         puts( -1 );         return -0;       }     }     cout << ans;   }   