func_code_string: #include <bits/stdc++.h>   template <class _, class __>   bool checkmax(_ &a, __ b) {     return a < b ? a = b, true : false;   }   template <class _, class __>   bool checkmin(_ &a, __ b) {     return a > b ? a = b, true : false;   }   using namespace std;   const int INF = 1e9;   struct node {     int x, p;     bool operator<(const node &a) const { return x < a.x; }   } A[200086];   int n, c, m;   stack<int> stk;   int nxt[200086];   int main() {     cin >> n >> c >> m;     for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) {       scanf( %d%d , &A[i].x, &A[i].p);     }     A[0] = (node){0, 0};     A[++m] = (node){n, INF};     sort(A, A + m + 1);     for (register int i = (m), i_end_ = (0); i >= i_end_; --i) {       while (!stk.empty() && A[stk.top()].p >= A[i].p) stk.pop();       nxt[i] = stk.empty() ? -1 : stk.top();       stk.push(i);     }     int rest = c;     long long ans = 0;     for (register int i = (1), i_end_ = (m); i <= i_end_; ++i) {       if (rest < A[i].x - A[i - 1].x) {         puts( -1 );         return EXIT_SUCCESS;       }       if (i == m) break;       rest -= A[i].x - A[i - 1].x;       if (nxt[i] != -1) {         int dis = A[nxt[i]].x - A[i].x;         if (rest >= dis) continue;         ans += 1ll * (min(dis, c) - rest) * A[i].p;         rest = min(dis, c);       } else {         if (rest >= A[m].x - A[i].x) continue;         ans += 1ll * (min(A[m].x - A[i].x, c) - rest) * A[i].p;         rest = min(A[m].x - A[i].x, c);       }     }     printf( %I64d n , ans);     return EXIT_SUCCESS;   }   